Submission #722451

#TimeUsernameProblemLanguageResultExecution timeMemory
722451definitelynotmeeSeats (IOI18_seats)C++17
100 / 100
2593 ms71248 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, sum; inline seg operator+(seg b){ b.sum+=sum; b.mn+=sum; if(mn == b.mn) b.ct+=ct; if(mn < b.mn){ b.ct = ct; b.mn = mn; } return b; } }; vector<seg> tree; int q, 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 update(int id, int l, int r){ if(l > q || r < q) return; if(q <= l && r <= q){ tree[id].mn+=val; tree[id].sum+=val; 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 v){ val = v; q = l; 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],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:107: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
  107 | #pragma endregion
      | 
seats.cpp: In function 'void update(int, int, int)':
seats.cpp:125:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |     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...