Submission #294477

#TimeUsernameProblemLanguageResultExecution timeMemory
294477amiratouSeats (IOI18_seats)C++14
31 / 100
4085 ms88184 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define sz(x) (int)(x.size()) const int MX = (int)(1e6+3); const int INF = (int)(1e9); typedef pair<int,int> ii; int ans[MX],sum[4*MX],lazy[4*MX],N; vector<int> X,Y; ii range[MX][2]; pair<ii,ii> st[4*MX]; void build(int node,int l,int r){ if(l==r){ st[node]={{X[l],X[l]},{Y[l],Y[l]}}; return; } int med=(l+r)>>1; build(node*2,l,med),build(node*2+1,med+1,r); st[node].fi={min(st[node*2].fi.fi,st[node*2+1].fi.fi),max(st[node*2].fi.se,st[node*2+1].fi.se)}; st[node].se={min(st[node*2].se.fi,st[node*2+1].se.fi),max(st[node*2].se.se,st[node*2+1].se.se)}; } void update(int node,int l,int r,int idx){ if(l>idx || r<idx) return; if(l==r){ st[node]={{X[l],X[l]},{Y[l],Y[l]}}; return; } int med=(l+r)>>1; update(node*2,l,med,idx),update(node*2+1,med+1,r,idx); st[node].fi={min(st[node*2].fi.fi,st[node*2+1].fi.fi),max(st[node*2].fi.se,st[node*2+1].fi.se)}; st[node].se={min(st[node*2].se.fi,st[node*2+1].se.fi),max(st[node*2].se.se,st[node*2+1].se.se)}; } void push(int node,int l,int r){ if(lazy[node]){ lazy[node]--; sum[node]=(r-l+1)*lazy[node]; if(l!=r){ lazy[node*2]=lazy[node]+1; lazy[node*2+1]=lazy[node]+1; } lazy[node]=0; } } void supdate(int node,int l,int r,int i,int j,int val){ push(node,l,r); if(l>j || r<i)return; if(l>=i && r<=j){ lazy[node]=val+1; push(node,l,r); return; } int med=(l+r)>>1; supdate(node*2,l,med,i,j,val),supdate(node*2+1,med+1,r,i,j,val); sum[node]=sum[node*2]+sum[node*2+1]; } int squery(int node,int l,int r,int i,int j){ push(node,l,r); if(l>j || r<i)return 0; if(l>=i && r<=j)return sum[node]; int med=(l+r)>>1; return squery(node*2,l,med,i,j)+squery(node*2+1,med+1,r,i,j); } pair<ii,ii> query(int node,int l,int r,int i,int j){ if(l>j || r<i) return {{INF,-1},{INF,-1}}; if(l>=i && r<=j)return st[node]; int med=(l+r)>>1; pair<ii,ii> q=query(node*2,l,med,i,j),q2=query(node*2+1,med+1,r,i,j); return {{min(q.fi.fi,q2.fi.fi),max(q.fi.se,q2.fi.se)},{min(q.se.fi,q2.se.fi),max(q.se.se,q2.se.se)}}; } void give_initial_chart(int H, int W, vector<int> R, vector<int> C) { X=R,Y=C; N=sz(X); build(1,0,N-1); for (int i = 0; i < H*W;) { pair<ii,ii> q=query(1,0,N-1,0,i); if(((q.fi.se-q.fi.fi+1)*(q.se.se-q.se.fi+1))==(i+1))supdate(1,0,N-1,i,i,1),i++; else i=((q.fi.se-q.fi.fi+1)*(q.se.se-q.se.fi+1))-1; } } int swap_seats(int a, int b) { if(a>b)swap(a,b); swap(X[a],X[b]),swap(Y[a],Y[b]); update(1,0,N-1,a),update(1,0,N-1,b); supdate(1,0,N-1,a,b,0); for (int i = a; i <= b;) { pair<ii,ii> q=query(1,0,N-1,0,i); if(((q.fi.se-q.fi.fi+1)*(q.se.se-q.se.fi+1))==(i+1))supdate(1,0,N-1,i,i,1),i++; else i=((q.fi.se-q.fi.fi+1)*(q.se.se-q.se.fi+1))-1; } return squery(1,0,N-1,0,N-1); }
#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...