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

#TimeUsernameProblemLanguageResultExecution timeMemory
447515blueSeats (IOI18_seats)C++17
100 / 100
2129 ms180944 KiB
#include "seats.h" #include <vector> #include <algorithm> #include <iostream> using namespace std; //seats -> 1-indexed, people -> 0-indexed const int INF = 1e9; const int maxHW = 1e6; int H; int W; vector<int> R; //row vector<int> C; //col vector< vector<int> > P; //person int* init; struct segtree { int l; int r; int lp; int mn; int count_mn; segtree* left = NULL; segtree* right = NULL; segtree() { ; } segtree(int L, int R) { l = L; r = R; lp = 0; if(l == r) { mn = init[l]; count_mn = 1; } else { int m = (l+r)/2; left = new segtree(l, m); right = new segtree(m+1, r); if(left->mn < right->mn) { mn = lp + left->mn; count_mn = left->count_mn; } else if(right->mn < left->mn) { mn = lp + right->mn; count_mn = right->count_mn; } else { mn = lp + left->mn; count_mn = left->count_mn + right->count_mn; } } } void range_add(int L, int R, int V) { if(R < l || r < L) return; else if(L <= l && r <= R) { lp += V; mn += V; } else { left->range_add(L, R, V); right->range_add(L, R, V); if(left->mn < right->mn) { mn = lp + left->mn; count_mn = left->count_mn; } else if(right->mn < left->mn) { mn = lp + right->mn; count_mn = right->count_mn; } else { mn = lp + left->mn; count_mn = left->count_mn + right->count_mn; } } } }; segtree S; void give_initial_chart(int h, int w, vector<int> r, vector<int> c) { H = h; W = w; R = r; C = c; for(int i = 0; i < H*W; i++) { R[i]++; C[i]++; } P = vector< vector<int> >(H+2); for(int i = 0; i <= H+1; i++) { P[i] = vector<int>(W+2, INF); } for(int i = 0; i < H*W; i++) { P[ R[i] ][ C[i] ] = i; } // cerr << "check\n"; vector<int> delta_init(1 + H*W, 0); for(int i = 0; i <= H; i++) { for(int j = 0; j <= W; j++) { vector<int> tmp{P[i][j], P[i+1][j], P[i][j+1], P[i+1][j+1]}; sort(tmp.begin(), tmp.end()); // S.range_add(tmp[0], tmp[1]-1, +1); if(tmp[0] < 1e8) delta_init[ tmp[0] ] += 1; if(tmp[1]-1 + 1 < 1e8) delta_init[ tmp[1]-1 + 1 ] -= 1; // S.range_add(tmp[2], tmp[3]-1, +10); if(tmp[2] < 1e8) delta_init[ tmp[2] ] += 10; if(tmp[3]-1 + 1 < 1e8) delta_init[ tmp[3]-1 + 1 ] -= 10; } } // cerr << "check\n"; init = new int[1 + H*W]; init[0] = delta_init[0]; for(int i = 1; i < H*W; i++) init[i] = delta_init[i] + init[i-1]; S = segtree(0, H*W - 1); // cerr << S.count_mn << '\n'; } int swap_seats(int a, int b) { vector<int> I; vector<int> J; for(int i = R[a]-1; i <= R[a]; i++) { for(int j = C[a]-1; j <= C[a]; j++) { I.push_back(i); J.push_back(j); } } for(int i = R[b]-1; i <= R[b]; i++) { for(int j = C[b]-1; j <= C[b]; j++) { I.push_back(i); J.push_back(j); } } for(int q = 0; q < I.size(); q++) { int i = I[q]; int j = J[q]; vector<int> tmp{P[i][j], P[i+1][j], P[i][j+1], P[i+1][j+1]}; sort(tmp.begin(), tmp.end()); S.range_add(tmp[0], tmp[1]-1, -1); S.range_add(tmp[2], tmp[3]-1, -10); } swap(P[ R[a] ][ C[a] ], P[ R[b] ][ C[b] ]); swap(R[a], R[b]); swap(C[a], C[b]); for(int q = 0; q < I.size(); q++) { int i = I[q]; int j = J[q]; vector<int> tmp{P[i][j], P[i+1][j], P[i][j+1], P[i+1][j+1]}; sort(tmp.begin(), tmp.end()); S.range_add(tmp[0], tmp[1]-1, +1); S.range_add(tmp[2], tmp[3]-1, +10); } return S.count_mn; }

Compilation message (stderr)

seats.cpp: In function 'int swap_seats(int, int)':
seats.cpp:205:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  205 |     for(int q = 0; q < I.size(); q++)
      |                    ~~^~~~~~~~~~
seats.cpp:224:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  224 |     for(int q = 0; q < I.size(); q++)
      |                    ~~^~~~~~~~~~
#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...