Jan.11th
注:黑粗体为超链接
今天CF萎到三点多……然后中午还要讲课……只能稍微做点BZOJ的水题了
众所周知的SB题……
匈牙利搞一搞搞不了就退出好了
C++ Code By WTRC
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 |
|
#include<cstdio>
#include<cstring> #include<algorithm> #include<cctype> #include<ctime> #include<cstdlib> #include<string> #include<queue> #define Rep(x,a,b) for (int x=a;x<=b;x++) #define Per(x,a,b) for (int x=a;x>=b;x--) #define ll long long using namespace std; inline int IN(){ int x=0,ch=getchar(),f=1; while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar(); if (ch=='-'){f=-1;ch=getchar();} while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*f; } int n,m; bool vis[1005]; int Link[1005]; int a[1005][2]; bool find(int u){ vis[u]=1; Rep(i,0,1) if (!Link[a[u][i]]){ Link[a[u][i]]=u; return 1; } else{ if (!vis[Link[a[u][i]]]&&find(Link[a[u][i]])){ Link[a[u][i]]=u; return 1; } } return 0; } int main(){ n=IN(),m=IN(); int Ans=0; Rep(i,1,m){ a[i][0]=IN(),a[i][1]=IN(); memset(vis,0,sizeof vis); if (find(i)) Ans++; else break; } printf("%d\n",Ans); } |
也是SB题一道……
先归并求逆序对然后每次修改的时候$O(n)$维护答案就行了
C++ Code By WTRC
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 |
|
#include<cstdio>
#include<cstring> #include<algorithm> #include<cctype> #include<ctime> #include<cstdlib> #include<string> #include<queue> #define Rep(x,a,b) for (int x=a;x<=b;x++) #define Per(x,a,b) for (int x=a;x>=b;x--) #define ll long long using namespace std; inline int IN(){ int x=0,ch=getchar(),f=1; while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar(); if (ch=='-'){f=-1;ch=getchar();} while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} return x*f; } int n,m,inv=0; int a[20005],b[20005],c[20005]; void UnionSort(int l,int r){ if (l==r) return; int mid=l+r>>1; UnionSort(l,mid);UnionSort(mid+1,r); int i=l,j=mid+1,cnt=l; while (i<=mid&&j<=r){ if (b[i]<=b[j]) c[cnt++]=b[i++]; else inv+=mid-i+1,c[cnt++]=b[j++]; } if (i<=mid) Rep(k,i,mid) c[cnt++]=b[k]; else Rep(k,j,r) c[cnt++]=b[k]; Rep(k,l,r) b[k]=c[k]; } int main(){ n=IN(); Rep(i,1,n) a[i]=IN(); memcpy(b,a,sizeof b); UnionSort(1,n); printf("%d\n",inv); m=IN(); Rep(i,1,m){ int p1=IN(),p2=IN(); if (p1>p2) swap(p1,p2); Rep(i,p1+1,p2-1){ if (a[i]<a[p2]) inv++;else if (a[i]>a[p2]) inv--; if (a[i]>a[p1]) inv++;else if (a[i]<a[p1]) inv--; } if (a[p1]<a[p2]) inv++;else if (a[p1]>a[p2]) inv--; swap(a[p1],a[p2]); printf("%d\n",inv); } } |
我题解都不好意思写
每次询问$O(n)$暴力操作一下就行
啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊做下次的课件做了一晚上啥题都没做 所以今天就这样了