90分求调-#7WA-梦幻布丁-启发式合并

P3201 [HNOI2009] 梦幻布丁

完整代码 ```cpp #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cmath> #include<map> #include<set> #include<queue> #include<vector> #include<limits.h> #define IL inline #define re register #define LL long long #define ULL unsigned long long #ifdef TH #define debug printf("Now is %d\n",__LINE__); #else #define debug #endif using namespace std; template<class T>inline void read(T&x) { char ch=getchar(); int fu; while(!isdigit(ch)&&ch!='-') ch=getchar(); if(ch=='-') fu=-1,ch=getchar(); x=ch-'0';ch=getchar(); while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();} x*=fu; } inline int read() { int x=0,fu=1; char ch=getchar(); while(!isdigit(ch)&&ch!='-') ch=getchar(); if(ch=='-') fu=-1,ch=getchar(); x=ch-'0';ch=getchar(); while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();} return x*fu; } int G[55]; template<class T>inline void write(T x) { int g=0; if(x<0) x=-x,putchar('-'); do{G[++g]=x%10;x/=10;}while(x); for(int i=g;i>=1;--i)putchar('0'+G[i]);putchar('\n'); } #define N 100010 int n,m; int a[N]; vector<int>color[N*10]; int ans; int f[N*10]; int getf(int x) { if(x==f[x]) return x; return f[x]=getf(f[x]); } int main() { // freopen("P3201_7.in","r",stdin); n=read(); m=read(); for(int i=1;i<=n;i++) { a[i]=read(); color[a[i]].push_back(i); } for(int i=1;i<N*10;i++) f[i]=i; ans=1; for(int i=2;i<=n;i++) { if(a[i]!=a[i-1]) ans++; } int op,x,y; while(m--) { op=read(); if(op==1) { x=read(); y=read(); x=getf(x); y=getf(y); if(x==y) continue; if(color[x].size()<color[y].size()) swap(x,y); for(int i=0;i<color[y].size();i++) { if(color[y][i]-1&&a[color[y][i]-1]==x) ans--; if(color[y][i]+1<=n&&a[color[y][i]+1]==x) ans--; } for(int i=0;i<color[y].size();i++) color[x].push_back(color[y][i]),a[color[y][i]]=x; color[y].clear(); f[y]=x; } else write(ans); // for(int i=1;i<=n;i++) cout<<a[i]<<" "; // cout<<endl; } return 0; } ```
by Vanilla_chan @ 2021-02-22 11:47:28


看到之前也有人90pts说是没有特判颜色相等,但是这里是有特判的。 ```cpp if(x==y) continue; ```
by Vanilla_chan @ 2021-02-22 11:49:11


对拍找到了一组DIFF ``` 14 26 9 10 17 7 12 21 1 15 24 4 24 13 17 6 1 14 8 2 1 7 2 1 12 4 1 10 12 1 15 4 2 1 10 7 2 2 1 14 7 1 13 1 2 1 6 11 1 8 15 1 3 7 1 1 4 2 2 2 1 6 8 2 1 8 15 1 13 2 2 2 ``` out ``` 14 14 13 13 13 12 12 12 12 12 12 ``` ans ``` 14 14 14 14 14 13 13 13 13 13 13 ```
by Vanilla_chan @ 2021-02-22 15:23:09


问题已解决。做法全假。
by Vanilla_chan @ 2021-02-22 16:06:43


|