UOJ Easy Round #1
http://vfleaking.blog.uoj.ac/blog/15
uoj 题解写的太好了。。。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include<queue> #include<cmath> #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T; ll g,l; int main() { T=read(); while(T--) { g=read();l=read(); ll mn=(ll)sqrt(l/g)*g; printf("%lld %lld\n",2*mn,l+g); } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
#include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int n,m,top; char ch[500005]; char q[500005]; struct trie{ int cnt,l; int a[500005][27],fail[500005],fa[500005]; char b[500005]; trie(){ cnt=1; } int insert(){ scanf("%s",ch+1); l=strlen(ch+1); if(ch[l]!='/')l++,ch[l]='/'; int now=1; for(int i=1;i<=l;i++) { int t=ch[i]-'a';if(ch[i]=='/')t=26; if(!a[now][t]) { a[now][t]=++cnt; fa[cnt]=now; b[cnt]=ch[i]; } now=a[now][t]; if(ch[i]=='/') { while(fail[now])now=fail[now]; } } return now; } }t; int main() { n=read();m=read(); for(int i=1;i<=n;i++) { int a=t.insert(),b=t.insert(); t.fail[a]=b; } while(m--) { int a=t.insert(); top=0; for(int i=a;i!=1;i=t.fa[i]) q[++top]=t.b[i]; if(top==1)puts("/"); else { int l=1; while(top>1)printf("%c",q[top--]); puts(""); } } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
#include<set> #include<map> #include<ctime> #include<queue> #include<cmath> #include<cstdio> #include<vector> #include<cstring> #include<cstdlib> #include<iostream> #include<algorithm> #define inf 1000000000 #define ll long long using namespace std; int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ll ans; int n,m,tot; int a[500005],b[500005],pas[500005]; int fa[300005],size[300005],pos[500005]; char ch[500005][10]; vector<int> Q; int find(int x) { return x==fa[x]?x:find(fa[x]); } void del(int K) { while(K--) { int t=Q[Q.size()-1]; if(pos[t]!=-1) { for(int i=fa[pos[t]];;i=fa[i]) { size[i]-=size[pos[t]]; if(i==fa[i])break; } fa[pos[t]]=pos[t]; ans-=t;tot--; } Q.pop_back(); } } int main() { n=read();m=read(); for(int i=1;i<=n;i++)fa[i]=i; for(int i=1;i<=n;i++)size[i]=1; for(int i=1;i<=m;i++) { scanf("%s",ch[i]+1); if(ch[i][1]=='A')a[i]=read(),b[i]=read(); if(ch[i][1]=='D')a[i]=read(); } for(int i=1;i<=m;i++) { if(ch[i][1]=='A') { int p=find(a[i]),q=find(b[i]); Q.push_back(i); if(p==q)pos[i]=-1; else { tot++;ans+=i; if(size[p]>size[q])swap(p,q); fa[p]=q;pos[i]=p; size[q]+=size[p]; } } if(ch[i][1]=='D') { if(ch[i+1][1]!='R') del(a[i]); else {printf("%d\n",pas[Q.size()-a[i]]);continue;} } if(ch[i][1]=='R'&&ch[i-1][1]=='A')del(1); if(tot!=n-1) { pas[Q.size()]=0; puts("0"); } else { pas[Q.size()]=ans; printf("%lld\n",ans); } } return 0; } |
Subscribe