Submission #722449

#TimeUsernameProblemLanguageResultExecution timeMemory
722449definitelynotmeeSeats (IOI18_seats)C++17
70 / 100
4080 ms86624 KiB
#include "seats.h" #include <bits/stdc++.h> #define ff first #define ss second #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; template<typename T> using matrix = vector<vector<T>>; int n, m; vector<int> v, rev; int translate(int x, int y){ return m*x+y; } pii detranslate(int id){ return {id/m,id%m}; } int getcount(pii coord, int t){ int dx[] = {0,0,1,1}, dy[] = {0,1,0,1}; int ret = 0; for(int i = 0; i < 4; i++){ int x = dx[i]+coord.ff, y = dy[i]+coord.ss; if(x < n && y < m && x >=0 && y >= 0){ ret+=v[translate(x,y)] <= t; } } return ret; } #pragma region seg struct SegTree{ struct seg{ int mn, ct, lz; seg operator+(seg b){ if(mn < b.mn) return *this; if(b.mn < mn) return b; b.ct+=ct; return b; } }; vector<seg> tree; int ql, qr, val, sz; void build(int id, int l, int r){ if(l == r){ tree[id] = {0,1,0}; return; } int e = id*2+1, d = id*2+2, m = (l+r)>>1; build(e,l,m); build(d,m+1,r); tree[id] = tree[e]+tree[d]; } SegTree(int n = 1){ tree.resize(4*n+4); sz = n; build(0,0,sz-1); } void refresh(int id, int l, int r){ if(tree[id].lz == 0) return; if(l != r){ int e = id*2+1, d = id*2+2, m = (l+r)>>1; tree[e].lz+=tree[id].lz; tree[d].lz+=tree[id].lz; } tree[id].mn+=tree[id].lz; tree[id].lz = 0; } void update(int id, int l, int r){ refresh(id,l,r); if(l > qr || r < ql) return; if(ql <= l && r <= qr){ tree[id].lz+=val; refresh(id,l,r); return; } int e = id*2+1, d = id*2+2, m = (l+r)>>1; update(e,l,m); update(d,m+1,r); tree[id] = tree[e] + tree[d]; } void makeupd(int l, int r, int v){ val = v; ql = l; qr = r; update(0,0,sz-1); } } st; #pragma endregion void update(int x, int y, int type = 1){ vector<int> vals; int dx[] = {0,0,1,1}, dy[] = {0,1,0,1}; for(int i = 0; i < 4; i++){ int xi = x+dx[i], yi = y + dy[i]; if(xi < n && yi < m && xi >=0 && yi >= 0){ vals.push_back(v[translate(xi,yi)]); } } sort(all(vals)); int summing[] = {1,-1,1,-1}; // cout << x << ' ' << y << endl; for(int i = 0; i < vals.size();i++){ // cout << "update " << vals[i] << ' ' << n*m-1 << " => " << summing[i]*type << endl; st.makeupd(vals[i],n*m-1,summing[i]*type); } } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { //cout << 'a' << endl; n = H; m = W; v = vector<int>(n*m); rev = vector<int>(n*m); for(int i = 0; i < n*m; i++){ v[R[i]*m+C[i]] = i; rev[i] = R[i]*m+C[i]; } st = SegTree(n*m); for(int x = -1; x < n; x++){ for(int y = -1; y < m; y++){ update(x,y); } } } int swap_seats(int a, int b) { array<pii,2> c({detranslate(rev[a]), detranslate(rev[b])}); int dx[] = {0,0,-1,-1}; int dy[] = {0,-1,-1,0}; for(int i = 0; i < 4; i ++){ for(int j = 0; j < 2; j++){ int x = c[j].ff + dx[i], y = c[j].ss + dy[i]; update(x,y,-1); } } swap(v[rev[a]],v[rev[b]]); swap(rev[a],rev[b]); for(int i = 0; i < 4; i ++){ for(int j = 0; j < 2; j++){ int x = c[j].ff + dx[i], y = c[j].ss + dy[i]; update(x,y,1); } } //cout << "-> " << st.tree[0].mn << ' ' << st.tree[0].ct << '\n'; return st.tree[0].ct; }

Compilation message (stderr)

seats.cpp:41: warning: ignoring '#pragma region seg' [-Wunknown-pragmas]
   41 |     #pragma region seg
      | 
seats.cpp:119: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  119 |     #pragma endregion
      | 
seats.cpp: In member function 'void SegTree::refresh(int, int, int)':
seats.cpp:86:45: warning: unused variable 'm' [-Wunused-variable]
   86 |                 int e = id*2+1, d = id*2+2, m = (l+r)>>1;
      |                                             ^
seats.cpp: In function 'void update(int, int, int)':
seats.cpp:137:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  137 |         for(int i = 0; i < vals.size();i++){
      |                        ~~^~~~~~~~~~~~~
#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...