Submission #1196481

#TimeUsernameProblemLanguageResultExecution timeMemory
1196481tkm_algorithmsSeats (IOI18_seats)C++17
17 / 100
4094 ms43908 KiB
/** * In the name of Allah * We are nothing and you're everything **/ #include <bits/stdc++.h> //#include "seats.h" using namespace std; using ll = long long; #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() //#define int ll const char nl = '\n'; const int N = 1e6+10; vector<int> r, c; vector<int> R_mins, R_maxs; vector<int> C_mins, C_maxs; int h, w, p[N]; int ans; void upd(int i) { R_mins[i] = r[i]; R_maxs[i] = r[i]; C_mins[i] = c[i]; C_maxs[i] = c[i]; if (i > 0) { R_mins[i] = min(R_mins[i], R_mins[i-1]); R_maxs[i] = max(R_maxs[i], R_maxs[i-1]); C_mins[i] = min(C_mins[i], C_mins[i-1]); C_maxs[i] = max(C_maxs[i], C_maxs[i-1]); } int calc = (R_maxs[i]-R_mins[i]+1)*(C_maxs[i]-C_mins[i]+1); if (calc == i+1) { if (p[i] == 0)ans += 1, p[i] = 1; } else { if (p[i] == 1)ans -= 1, p[i] = 0; } } void give_initial_chart(int H, int W, std::vector<int> R, std::vector<int> C) { r = R, c = C; h = H, w = W; R_mins.assign(h*w, h*w); C_mins.assign(h*w, h*w); R_maxs.assign(h*w, 0); C_maxs.assign(h*w, 0); memset(p, 0, sizeof p); for (int i = 0; i < h*w; ++i) upd(i); } int swap_seats(int a, int b) { swap(r[a], r[b]); swap(c[a], c[b]); if (a > b)swap(a, b); for (int i = a; i <= b; ++i) upd(i); return ans; } //void solve() { //int H, W, Q; //cin >> H >> W >> Q; //vector<int> R, C; //R.resize(H*W); C.resize(H*W); //for (int i = 0; i < H*W; ++i)cin >> R[i] >> C[i]; //give_initial_chart(H, W, R, C); //while (Q--) { //int a, b; cin >> a >> b; //cout << swap_seats(a, b) << nl; //} //} //int32_t main() { //ios::sync_with_stdio(0); //cin.tie(0); //int t = 1; //for (int _ = 0; _ < t; ++_) { //solve(); //} //return 0; //}
#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...