Submission #418621

#TimeUsernameProblemLanguageResultExecution timeMemory
418621cfalasSeats (IOI18_seats)C++14
5 / 100
4083 ms141356 KiB
#include "seats.h" #include<bits/stdc++.h> using namespace std; #define mp make_pair #define INF 10000000 #define MOD 10000000 #define MID ((l+r)/2) #define HASHMOD 2305843009213693951 #define ll long long #define ull unsigned long long #define F first #define S second typedef pair<ll, ll> ii; typedef pair<ii, int> iii; typedef vector<int> vi; typedef vector<ii> vii; typedef map<int, int> mii; #define EPS 1e-6 #define FOR(i,n) for(int i=0;i<((int)(n));i++) #define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++) #define FOA(v, a) for(auto v : a) int n, m; struct seg_tree{ seg_tree *left; seg_tree *right; ii mina={MOD, MOD}; ii maxa={0,0}; void update(ii val, int x, int l=0, int r=MOD){ //cout<<"B "<<l<<" "<<r<<" "<<mina.F<<" "<<mina.S<<endl; if(l==r && l==x){ mina = val; maxa = val; } else if(l>x || r<x) return; else{ if(!left) left = new seg_tree; if(!right) right = new seg_tree; left->update(val, x, l, MID); right->update(val, x, MID+1, r); mina = {min(left->mina.F, right->mina.F), min(left->mina.S, right->mina.S)}; maxa = {max(left->maxa.F, right->maxa.F), max(left->maxa.S, right->maxa.S)}; //cout<<l<<" "<<r<<" "<<mina.F<<" "<<mina.S<<endl; } } pair<ii,ii> query(int rl, int rr, int l=0, int r=MOD){ if(rl<=l && r<=rr) return {mina, maxa}; else if(r<rl || rr<l) return {{MOD, MOD}, {0, 0}}; else{ pair<ii, ii> ans1 = {{MOD, MOD}, {0, 0}}; pair<ii, ii> ans2 = {{MOD, MOD}, {0, 0}}; if(left) ans1 = left->query(rl, rr, l, MID); if(right) ans2 = right->query(rl,rr,MID+1, r); ii a1 = {min(ans1.F.F, ans2.F.F), min(ans1.F.S, ans2.F.S)}; ii a2 = {max(ans1.S.F, ans2.S.F), max(ans1.S.S, ans2.S.S)}; return {a1, a2}; } } }; seg_tree seg; void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { //cout<<"STARTED"<<endl; n = H, m = W; FOR(i, n*m){ seg.update({R[i], C[i]}, i); } //cout<<"DONE"<<endl; } int swap_seats(int a, int b) { pair<ii, ii> temp1 = seg.query(a, a); pair<ii, ii> temp2 = seg.query(b, b); //cout<<temp1.F.F<<" "<<temp1.F.S<<" "<<temp1.S.F<<" "<<temp1.S.S<<endl; seg.update(temp1.F, b); seg.update(temp2.F, a); int r=0; FOR(i, n*m){ pair<ii, ii> ans = seg.query(0, i); //cout<<ans.F.F<<" "<<ans.F.S<<" "<<ans.S.F<<" "<<ans.S.S<<endl; int q = (abs(ans.F.F - ans.S.F)+1) * (abs(ans.S.S - ans.F.S)+1); //cout<<q<<endl; if(q==i+1) r++; } return r; }
#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...