Submission #259807

#TimeUsernameProblemLanguageResultExecution timeMemory
259807shayan_pSweeping (JOI20_sweeping)C++14
1 / 100
17139 ms2097156 KiB
// And you curse yourself for things you never done #include<bits/stdc++.h> #define F first #define S second #define PB push_back #define sz(s) int((s).size()) #define bit(n,k) (((n)>>(k))&1) using namespace std; typedef long long ll; typedef pair<int,int> pii; const int maxn = 1e6 + 10, mod = 1e9 + 7, inf = 1e9 + 10; struct node{ map<int, int> mp; void add(int f, int s, int x){ auto L = mp.upper_bound(f); int col = -1; if(L != mp.begin()) col = prev(L)->S; auto R = L; while(R != mp.end() && (R->F) <= s) col = R->S, R++; mp[f] = x; mp[s] = col; } int ask(int pos){ auto it = mp.upper_bound(pos); if(it == mp.begin()) return -1; return prev(it)->S; } }; vector<int> arr; struct node2{ node2 *L, *R; node* s; node2(){ L = R = 0; s = 0; } void add(int fx, int sx, int fy, int sy, int x, int l = 0, int r = sz(arr) - 1){ if(fx <= arr[l] && arr[r] <= sx){ if(s == 0) s = new node(); s->add(fy, sy, x); return; } int mid = (l+r) >> 1; if(sx > arr[l] && arr[mid] > fx){ if(L == 0) L = new node2(); L->add(fx, sx, fy, sy, x, l, mid); } if(sx > arr[mid] && arr[r] > fx){ if(R == 0) R = new node2(); R->add(fx, sx, fy, sy, x, mid, r); } } int ask(int posx, int posy, int l = 0, int r = sz(arr) - 1){ int mid = (l+r) >> 1; if(posx < arr[mid]){ int ans = -1; if(s) ans = s->ask(posy); if(L) ans = max(ans, L->ask(posx, posy, l, mid)); return ans; } else{ int ans = -1; if(s) ans = s->ask(posy); if(R) ans = max(ans, R->ask(posx, posy, mid, r)); return ans; } } }; int N; pii trans(pii p){ // x1 x2 return {p.S, N - p.F}; } pii trans2(pii p){ // x1 x2 return {p.F, N - p.S}; } struct bigTraingle{ map<pii, pii> mp; vector<pii> to; node2* rt; void restart(){ mp.clear(); to.clear(); rt = new node2(); ins({0, N}, {0, 0}); } pii color(pii p){ int c = rt->ask(p.F, p.S); return to[c]; } void put(pii l, pii r, pii x){ rt->add(l.F, r.F + 1, l.S, r.S + 1, sz(to)); to.PB(x); } void ins(pii a, pii b){ mp[a] = b; put(b, trans(a), a); } void add(int l, bool is){ int x = l, y = N - l; if(is) swap(x, y); auto it = --mp.upper_bound({x, inf}); int L = it->F.F, R = it->F.S; pii p = it->S; mp.erase(it); if(!is){ pii A = {L, x}, B = {x + 1, R}; ins(A, p); if(B.F <= B.S) ins(B, {B.F, p.S}); } else{ pii A = {L, x - 1}, B = {x, R}; ins(B, p); if(A.F <= A.S) ins(A, {p.F, N - A.S}); } } pii calc(pii p){ pii s = color(p); pii A = mp[s], B = trans(s), C = trans2(s); assert(A.F <= p.F && A.S <= p.S && p.F <= B.F && p.S <= B.S); return {max(C.F, p.F), max(C.S, p.S)}; } }; bigTraingle tr[20]; vector<int> ids[20]; int who[maxn]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(); int m, q; cin >> N >> m >> q; vector<pii> p; for(int i = 0; i < 20; i++){ if(bit(m, i)){ for(int j = 0; j < (1<<i); j++){ int x, y; cin >> x >> y; who[sz(p)] = i; ids[i].PB(sz(p)); p.PB({x, y}); } } } stringstream CIN; for(int i = 0; i < q; i++){ int task, a, b; cin >> task >> a; CIN << task << " " << a << " "; if(task == 4){ cin >> b; CIN << b << " "; } if(task == 2){ arr.PB(N - a); arr.PB(a+2); } if(task == 3){ arr.PB(a + 1); } } arr.PB(0); arr.PB(N); sort(arr.begin(), arr.end()); arr.resize( unique(arr.begin(), arr.end()) - arr.begin() ); // should be next of arr for(int i = 0; i < 20; i++){ tr[i].restart(); } while(q--){ int task; CIN >> task; if(task == 1){ int id; CIN >> id; --id; pii ans = tr[who[id]].calc(p[id]); cout << ans.F << " " << ans.S << "\n"; } if(task == 2){ int l; CIN >> l; for(int i = 0; i < 20; i++) if(!ids[i].empty()) tr[i].add(l, 1); } if(task == 3){ int l; CIN >> l; for(int i = 0; i < 20; i++) if(!ids[i].empty()) tr[i].add(l, 0); } if(task == 4){ int x, y; CIN >> x >> y; vector<int> vv; vv.PB(sz(p)); p.PB({x, y}); int pt = 0; while(!ids[pt].empty()){ for(int x : ids[pt]) vv.PB(x), p[x] = tr[pt].calc(p[x]); ids[pt].clear(); tr[pt].restart(); pt++; } swap(ids[pt], vv); for(int x : ids[pt]){ who[x] = pt; } } } return 0; }
#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...