(UPD: 2024-12-04 14:48 UTC) Judge is not working due to Cloudflare incident. (URL) We can do nothing about it, sorry. After the incident is resolved, we will grade all submissions.

Submission #1106680

#TimeUsernameProblemLanguageResultExecution timeMemory
1106680snpmrnhlolSeats (IOI18_seats)C++17
31 / 100
3645 ms70984 KiB
#include "seats.h" #include <bits/stdc++.h> using namespace std; const int N = 15e2; struct nod{ int mn,mx; }seg[2][4*N*N]; nod operator+(nod a, nod b){ return {min(a.mn,b.mn),max(a.mx,b.mx)}; } int sz; void upd(int pos, int x, int y, int l = 0, int r = sz - 1, int node = 1){ if(l == r){ seg[0][node] = {x, x}; seg[1][node] = {y, y}; }else{ int mij = (l + r)/2; if(pos <= mij){ upd(pos, x, y, l, mij, node*2); }else{ upd(pos, x, y, mij + 1, r, node*2 + 1); } seg[0][node] = seg[0][node*2] + seg[0][node*2 + 1]; seg[1][node] = seg[1][node*2] + seg[1][node*2 + 1]; } } nod query(int ql, int qr, int id, int l = 0, int r = sz - 1, int node = 1){ if(r < ql || qr < l)return {sz, -1}; if(ql <= l && r <= qr){ return seg[id][node]; }else{ int mij = (l + r)/2; return query(ql, qr, id, l, mij, node*2) + query(ql, qr, id, mij + 1, r, node*2 + 1); } } std::vector<std::vector<int>> v; vector <int> x,y; int n,m; void give_initial_chart(int n2, int m2, std::vector<int> a, std::vector<int> b) { n = n2;m = m2; v.assign(n, vector<int>(m,0)); x = a; y = b; sz = n*m; for(int i = 0;i < n*m;i++){ v[x[i]][y[i]] = i; upd(i, x[i], y[i]); } } int swap_seats(int a, int b){ swap(x[a],x[b]); swap(y[a],y[b]); upd(a, x[a], y[a]); upd(b, x[b], y[b]); swap(v[x[a]][y[a]],v[x[b]][y[b]]); int ans = 0; int ans2 = 0; if(n + m <= 2000){ int i = 0; while(i < n*m){ nod p1 = query(0, i, 0); nod p2 = query(0, i, 1); int matrixsz = (p1.mx - p1.mn + 1)*(p2.mx - p2.mn + 1); if(matrixsz == i + 1){ ans++; } i = max(i + 1, matrixsz - 1); } }else if(n*m <= 10000){ int r = -1,l = m,d = -1,u = n; for(int i = 0;i < n*m;i++){ l = min(l,y[i]); r = max(r,y[i]); u = min(u,x[i]); d = max(d,x[i]); if((r - l + 1)*(d - u + 1) == i + 1){ ans2++; } } } return max(ans,ans2); }
#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...