제출 #991350

#제출 시각아이디문제언어결과실행 시간메모리
991350PCTprobability자리 배치 (IOI18_seats)C++17
0 / 100
1296 ms262144 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; struct segtree{ vector<int> node; int n; segtree(){ } segtree(int n_){ n=1; while(n<n_) n*=2; node.resize(2*n); for(int i=0;i<2*n;i++) node[i]=10101010; } void set(int x,int v){ x+=n; node[x]=v; while(x>1){ x/=2; node[x]=min(node[2*x],node[2*x+1]); } } int prod(int l,int r,int a,int b,int k){ if(r<=a||b<=l) return 10101010; if(l<=a&&b<=r) return node[k]; return min(prod(l,r,a,(a+b)/2,2*k),prod(l,r,(a+b)/2,b,2*k+1)); } int prod(int l,int r){ return prod(l,r,0,n,1); } }; //max struct segtree2{ vector<int> node; int n; segtree2(){ } segtree2(int n_){ n=1; while(n<n_) n*=2; node.resize(2*n); for(int i=0;i<2*n;i++) node[i]=-10101010; } void set(int x,int v){ x+=n; node[x]=v; while(x>1){ x/=2; node[x]=max(node[2*x],node[2*x+1]); } } int prod(int l,int r,int a,int b,int k){ if(r<=a||b<=l) return -10101010; if(l<=a&&b<=r) return node[k]; return max(prod(l,r,a,(a+b)/2,2*k),prod(l,r,(a+b)/2,b,2*k+1)); } int prod(int l,int r){ return prod(l,r,0,n,1); } }; int r[1010101],c[1010101]; segtree rsg,csg; segtree2 rsg2,csg2; int n,m; int ans=0; set<int> rs[1010101],cs[1010101]; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { n=H,m=W; for(int i=0;i<n*m;i++){ r[i]=R[i]; c[i]=C[i]; rs[r[i]].insert(i); cs[c[i]].insert(i); } segtree se(n*m),se3(n*m); segtree2 se2(n*m),se4(n*m); for(int i=0;i<n*m;i++){ se.set(i,r[i]); se2.set(i,r[i]); se3.set(i,c[i]); se4.set(i,c[i]); } rsg=se,csg=se3,rsg2=se2,csg2=se4; } int swap_seats(int a, int b) { int ans=0; rs[r[a]].erase(a); cs[c[a]].erase(a); rs[r[b]].erase(b); cs[c[b]].erase(b); swap(r[a],r[b]); swap(c[a],c[b]); rs[r[a]].insert(a); rs[r[b]].insert(b); cs[c[a]].insert(a); cs[c[b]].insert(b); rsg.set(a,r[a]); rsg.set(b,r[b]); rsg2.set(a,r[a]); rsg2.set(b,r[b]); csg.set(a,c[a]); csg.set(b,c[b]); csg2.set(a,c[a]); csg2.set(b,c[b]); set<int> idx; //for(int i=0;i<n;i++) idx.insert(*rs[i].begin()); //for(int i=0;i<m;i++) idx.insert(*cs[i].begin()); idx.insert(n*m); for(auto e:idx){ int t=e-1; if(t<0) continue; if((rsg2.prod(0,t+1)-rsg.prod(0,t+1)+1)*(csg2.prod(0,t+1)-csg.prod(0,t+1)+1)==t+1) ans++; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...