gplt2021 codeing review
L2-4
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=1e5+1;
unordered_map<int,int>op[N];
int now=1;
int mark[100];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=100;++i)
mark[i]=1;
for(int i=1;i<=n;++i){
int k;
cin>>k;
for(int j=1,to;j<=k;++j){
cin>>to;
op[i][j]=to;
}
}
for(int i=1;i<=m;++i){
int d,x;
cin>>d;
if(d==0){
cin>>x;
now=op[now][x];
}
else if(d==1){
cin>>x;
mark[x]=now;
cout<<now<<'
';
}
else if(d==2){
cin>>x;
now=mark[x];
}
}
cout<<now<<'
';
}
L2-3
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
map<vector<int>,int>fk;
struct node{
vector<int>op;
int cnt;
};
inline bool cmp(node &a,node &b){
if(a.cnt!=b.cnt)
return a.cnt>b.cnt;
return a.op<b.op;
}
vector<node>vn;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n>>m;
vector<int>vk(m);
for(int i=1;i<=n;++i){
for(int j=0;j<m;++j)
cin>>vk[j];
fk[vk]++;
}
for(auto &i:fk){
vn.pb({i.fi,i.se});
}
sort(all(vn),cmp);
cout<<sz(vn)<<'
';
for(int i=0;i<sz(vn);++i){
cout<<vn[i].cnt<<" ";
for(int j=0;j<sz(vn[i].op);++j){
cout<<vn[i].op[j]<<"
"[j==sz(vn[i].op)-1];
}
}
}
L2-2
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=1e4+1;
int hfa[N];
int fa[N];
//struct node{
// int to;
//};
vector<int>E[N];
vector<int>path,ans;
int vis[N];
void dfs(int u){
path.pb(u);
vis[u]=1;
for(auto v:E[u]){
dfs(v);
}
if(sz(path)>sz(ans)){
ans=path;
}
else if(sz(path)==sz(ans)){
if(path<ans)
ans=path;
}
path.pop_back();
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
for(int i=0,k;i<n;++i){
cin>>k;
for(int j=1,v;j<=k;++j){
cin>>v;
fa[v]=i;
hfa[v]=1;
E[i].pb(v);
}
}
for(int i=0;i<n;++i){
path.clear();
if(vis[i]==0)
dfs(i);
}
cout<<sz(ans)<<'
';
for(int i=0;i<sz(ans);++i)
cout<<ans[i]<<"
"[i==sz(ans)-1];
}
L2-1
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m,sm;
cin>>n>>m>>sm;
string s;
for(int i=1;i<=n;++i){
cin>>s;
for(auto c:s)
gd[i].pb(c);
}
int op;
while(1){
cin>>op;
if(op==-1)break;
if(op==0){
do0();
}
else{
if(gd[op].empty()==0){
if(sz(kua)==sm){
do0();
}
kua.pb(gd[op].front());
gd[op].pop_front();
}
}
}
for(int i=0;i<sz(liu);++i)
cout<<liu[i];
}
L1-8
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int a,b,n;
cin>>a>>b>>n;
vector<int>v={a,b};
for(int i=0;;++i){
if(sz(v)>=n) break;
int now=v[i]*v[i+1];
string t=to_string(now);
for(auto j:t){
v.pb(j-'0');
}
}
for(int i=0;i<n;++i)
cout<<v[i]<<"
"[i==n-1];
}
L1-7
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n;
cin>>n;
map<int,int>ma;
for(int i=1,w;i<=n;++i){
cin>>w;
ma[w]++;
}
int val,cnt;
tie(val,cnt)=*(ma.begin());
cout<<val<<' '<<cnt<<'
';
tie(val,cnt)=*(ma.rbegin());
cout<<val<<' '<<cnt<<'
';
}
L1-6
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
string s1="qiandao",s2="easy",s3="Wo AK le";
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n>>m;
string s;
int com=0;
// getline(cin,s);
for(int i=1;i<=n;++i){
getline(cin,s);
while(s.empty()||(s.size()&&(s[0]=='
'||s[0]=='
')))getline(cin,s);
int check=0;
for(int j=0;j<sz(s)&&check==0;++j){
int pass0=0,pass1=0;
for(int k=0;k<sz(s1);k++){
if(j+k>=sz(s)||s1[k]!=s[j+k])break;
if(k==sz(s1)-1)pass0=1;
}
for(int k=0;k<sz(s2);k++){
if(j+k>=sz(s)||s2[k]!=s[j+k])break;
if(k==sz(s2)-1)pass1=1;
}
if(pass0||pass1)check=1;
}
if(com==m){
cout<<s;
return 0;
}
// cout<<endl;
// dd(i)dd(com)de(check)
// cout<<endl;
if(check)continue;
com++;
}
cout<<s3;
}
L1-4
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
string s1="On Sale! ",s2="easy",s3="Wo AK le";
int xq[1001];
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
n=24;
for(int i=0;i<n;++i){
cin>>m;
xq[i]=m;
}
while(cin>>m){
if(m>=0&&m<n){
cout<<xq[m];
if(xq[m]>50){
cout<<" Yes
";
}
else{
cout<<" No
";
}
}
else break;
}
}
L1-3
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
string s1="On Sale! ",s2="easy",s3="Wo AK le";
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i){
db s;
cin>>s;
if(s<m){
cout<<s1<<fixed<<setprecision(1)<<s<<'
';
}
}
}
L1-2
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=100+1;
deque<char>gd[N];
vector<char>kua;
vector<char>liu;
void do0(){
if(kua.empty()){
}
else{
liu.pb(kua.back());
kua.pop_back();
}
}
string s1="qiandao",s2="easy",s3="Wo AK le";
int main(){
ios::sync_with_stdio(0);cin.tie(0);
string s;
cin>>s;
if(sz(s)==4){
int t1=(s[0]-'0')*10+s[1]-'0';
if(t1<22){
cout<<20<<s.substr(0,2)<<'-'<<s[2]<<s[3];
}
else{
cout<<19<<s.substr(0,2)<<'-'<<s[2]<<s[3];
}
}
else{
cout<<s.substr(0,4)<<'-'<<s.substr(4,2);
}
}
L1-1
#include<bits/stdc++.h>
using namespace std;
int main(){
puts("To iterate is human, to recurse divine.");
}
L3-1
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<'
';
const ll N=1e5+1;
struct node{
ll to,cost;
};
vector<node>E[N];
vector<node>E2[N];
ll a[N];
ll d[N],d2[N];
void Dij(int s){
ll D,x,y;
fill(d,d+N,-1);
priority_queue<pii,vector<pii>,greater<pii>>pr;
pr.emplace(d[s]=0,s);
for(;!pr.empty();){
tie(D,x)=pr.top();pr.pop();
if(D!=d[x])continue;
for(auto i:E[x]){
if(D+i.cost<d[y=i.to]||d[y]==-1){
pr.emplace(d[y]=D+i.cost,y);
}
}
}
}
void Dij2(int s){
ll D,x,y;
fill(d2,d2+N,-1);
priority_queue<pii,vector<pii>,greater<pii>>pr;
pr.emplace(d2[s]=0,s);
for(;!pr.empty();){
tie(D,x)=pr.top();pr.pop();
if(D!=d2[x])continue;
for(auto i:E2[x]){
if(D+i.cost<d2[y=i.to]||d2[y]==-1){
pr.emplace(d2[y]=D+i.cost,y);
}
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n,m,q;
cin>>n>>m>>q;
for(ll i=1,u,v,c,d;i<=m;++i){
cin>>u>>v>>c>>d;
if(u==v)continue;
E[u].pb({v,c});
E2[v].pb({u,d});
}
for(ll i=1;i<=n;++i){
cin>>a[i];
}
Dij(1);
Dij2(n);
multiset<ll>ans;
for(int j=1;j<=n;++j){
if(d[j]!=-1&&d2[j]!=-1)
ans.insert(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0));
}
// cout<<ans<<endl;
for(ll i=1,id,w;i<=q;++i){
cin>>id>>w;
if(n==1){
cout<<0<<endl;
continue;
}
int j=id;
if(d[j]!=-1&&d2[j]!=-1){
ans.erase(ans.lower_bound(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0)));
a[id]=w;
ans.insert(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0));
}
cout<<*(ans.begin())<<'
';
}
}
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<ll,ll>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<'
';
const ll N=1e5+1;
struct node{
ll to,cost;
};
vector<node>E[N];
vector<node>E2[N];
ll a[N];
ll d[N],d2[N];
void Dij(int s){
ll D,x,y;
fill(d,d+N,LLONG_MAX/4);
priority_queue<pii,vector<pii>,greater<pii>>pr;
pr.emplace(d[s]=0,s);
for(;!pr.empty();){
tie(D,x)=pr.top();pr.pop();
if(D!=d[x])continue;
for(auto i:E[x]){
if(D+i.cost<d[y=i.to]){
pr.emplace(d[y]=D+i.cost,y);
}
}
}
}
void Dij2(int s){
ll D,x,y;
fill(d2,d2+N,LLONG_MAX/4);
priority_queue<pii,vector<pii>,greater<pii>>pr;
pr.emplace(d2[s]=0,s);
for(;!pr.empty();){
tie(D,x)=pr.top();pr.pop();
if(D!=d2[x])continue;
for(auto i:E2[x]){
if(D+i.cost<d2[y=i.to]){
pr.emplace(d2[y]=D+i.cost,y);
}
}
}
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
ll n,m,q;
cin>>n>>m>>q;
for(ll i=1,u,v,c,d;i<=m;++i){
cin>>u>>v>>c>>d;
if(u==v)continue;
E[u].pb({v,c});
E2[v].pb({u,d});
}
for(ll i=1;i<=n;++i){
cin>>a[i];
}
Dij(1);
Dij2(n);
multiset<ll>ans;
for(int j=1;j<=n;++j){
ans.insert(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0));
}
// cout<<ans<<endl;
for(ll i=1,id,w;i<=q;++i){
cin>>id>>w;
if(n==1){
cout<<0<<endl;
continue;
}
int j=id;
ans.erase(ans.lower_bound(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0)));
a[id]=w;
ans.insert(d[j]+d2[j]/a[j]+(d2[j]%a[j]!=0));
cout<<*(ans.begin())<<'
';
}
}
L3-2
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
using ull=unsigned long long;
using pii=pair<int,int>;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define dd(x) cerr<<fixed<<#x<<" = "<<x<<' ';
#define de(x) cerr<<fixed<<#x<<" = "<<x<<' ';
const int N=1e5+1;
struct node{
vector<int>ps;
int id;
}f[101];
int pss[N],vis[N];
inline bool cmp(node &a,node &b){
return sz(a.ps)>sz(b.ps);
}
map<int,vector<int>>Next;
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int n,m;
cin>>n;
for(int i=0;i<n;++i){
cin>>pss[i];
Next[pss[i]].pb(i);
}
cin>>m;
for(int i=1,l;i<=m;++i){
f[i].id=i;
cin>>l;
f[i].ps.resize(l);
for(int j=0;j<l;++j)
cin>>f[i].ps[j];
}
sort(f+1,f+m+1,cmp);
for(int i=1;i<=m;++i){
auto& nb=Next[f[i].ps[0]];
for(int j:nb){
// int check=0;
int match=0,cfilct=0;
for(int k=0;k<sz(f[i].ps);++k){
if(j+k<n&&f[i].ps[k]==pss[j+k]){
match++;
if(vis[j+k])cfilct++;
}
}
if(cfilct<=2&&match==sz(f[i].ps)){
for(int k=0;k<sz(f[i].ps);++k){
vis[j+k]=f[i].id;
}
break;
}
}
}
vector<int>ans;
int last=0;
for(int i=0;i<n;++i){
if(vis[i]!=last){
ans.pb(vis[i]);
}
last=vis[i];
}
for(int i=0;i<sz(ans);++i){
cout<<ans[i]<<"
"[i==sz(ans)-1];
}
}
L3-3