(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 #722456

#TimeUsernameProblemLanguageResultExecution timeMemory
722456definitelynotmeeSeats (IOI18_seats)C++17
100 / 100
2587 ms72020 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; inline int translate(int x, int y){ return m*x+y; } inline pii detranslate(int id){ return {id/m,id%m}; } 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]; } inline void makeupd(int l, int v){ val = v; q = l; update(0,0,sz-1); } } st; inline 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: In function 'void update(int, int, int)':
seats.cpp:106:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |     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...