Submission #1190602

#TimeUsernameProblemLanguageResultExecution timeMemory
1190602epicci23Mosaic (IOI24_mosaic)C++20
12 / 100
171 ms83152 KiB
#include "bits/stdc++.h" //#include "mosaic.h" #define ll long long #define all(v) v.begin() , v.end() #define sz(a) (ll)a.size() using namespace std; const ll N = 2e5 + 5; ll n, q; ll ans[N], row[N], col[N]; ll ar[N][6], v[6][N], dp_ar[N][6], dp_v[6][N]; vector<array<ll,4>> to_calc; vector<array<ll,2>> ones; vector<ll> mosaic(vector<int> X, vector<int> Y, vector<int> T, vector<int> B, vector<int> L, vector<int> R) { n = sz(X); for(int i = 1; i <= n; i++) col[i] = X[i-1]; for(int i = 1; i <= n; i++) row[i] = Y[i-1]; for(int i = 1; i <= n; i++){ for(int j = 1; j <= 5; j++){ if(i == 1) ar[i][j] = col[j]; else if(j == 1) ar[i][j] = row[i]; else ar[i][j] = min(1 - ar[i-1][j], 1 - ar[i][j-1]); dp_ar[i][j] = dp_ar[i-1][j] + dp_ar[i][j-1] - dp_ar[i-1][j-1] + (ar[i][j] == 1); } } for(int i = 1; i <= 5; i++){ for(int j = 1; j <= n; j++){ if(i == 1) v[i][j] = col[j]; else if(j == 1) v[i][j] = row[i]; else v[i][j] = min(1 - v[i-1][j], 1 - v[i][j-1]); dp_v[i][j] = dp_v[i-1][j] + dp_v[i][j-1] - dp_v[i-1][j-1] + (v[i][j] == 1); } } for(int i = n; i >= 5; i--){ if(ar[i][5] == 1){ ones.push_back({i, 5}); } } for(int j = 6; j <= n; j++){ if(v[5][j] == 1){ ones.push_back({5, j}); } } q = sz(B); for(int i=0;i<q;i++){ int t = T[i] + 1, b = B[i] + 1, l = L[i] + 1, r = R[i] + 1; to_calc.push_back({b, r, i, 1}); to_calc.push_back({b, l - 1, i, -1}); to_calc.push_back({t - 1, r, i, -1}); to_calc.push_back({t - 1, l - 1, i, 1}); } for(array<ll,4> X : to_calc){ if(X[0] == 0 || X[1] == 0) continue; if(X[0] >= 5 && X[1] >= 5){ ll res = dp_v[4][X[1]] + dp_ar[X[0]][4] - dp_v[4][4]; ll l = lower_bound(all(ones), array<ll,2>{X[0], 5}) - ones.begin(); ll r = upper_bound(all(ones), array<ll,2>{5, X[1]}) - ones.begin(); r--; for(int u = l; u <= r; u++) res += min(X[0] - ones[u][0] + 1, X[1] - ones[u][1] + 1); // opt here! ans[X[2]] += X[3] * res; } else{ if(X[0] < 5) ans[X[2]] += X[3] * dp_v[X[0]][X[1]]; else ans[X[2]] += X[3] * dp_ar[X[0]][X[1]]; } } vector<ll> res(q); for(int i=0;i<q;i++) res[i] = ans[i]; return res; } /*void _(){ cin >> n; for(int i = 1; i <= n; i++) cin >> col[i]; for(int i = 1; i <= n; i++) cin >> row[i]; for(int i = 1; i <= n; i++){ for(int j = 1; j <= 5; j++){ if(i == 1) ar[i][j] = col[j]; else if(j == 1) ar[i][j] = row[i]; else ar[i][j] = min(1 - ar[i-1][j], 1 - ar[i][j-1]); dp_ar[i][j] = dp_ar[i-1][j] + dp_ar[i][j-1] - dp_ar[i-1][j-1] + (ar[i][j] == 1); } } for(int i = 1; i <= 5; i++){ for(int j = 1; j <= n; j++){ if(i == 1) v[i][j] = col[j]; else if(j == 1) v[i][j] = row[i]; else v[i][j] = min(1 - v[i-1][j], 1 - v[i][j-1]); dp_v[i][j] = dp_v[i-1][j] + dp_v[i][j-1] - dp_v[i-1][j-1] + (v[i][j] == 1); } } for(int i = n; i >= 5; i--){ if(ar[i][5] == 1){ ones.push_back({i, 5}); } } for(int j = 6; j <= n; j++){ if(v[5][j] == 1){ ones.push_back({5, j}); } } cin >> q; for(int i=1;i<=q;i++){ int t, b, l, r; cin >> t >> b >> l >> r; to_calc.push_back({b, r, i, 1}); to_calc.push_back({b, l - 1, i, -1}); to_calc.push_back({t - 1, r, i, -1}); to_calc.push_back({t - 1, l - 1, i, 1}); } for(array<int,4> X : to_calc){ if(X[0] == 0 || X[1] == 0) continue; if(X[0] >= 5 && X[1] >= 5){ int res = dp_v[4][X[1]] + dp_ar[X[0]][4] - dp_v[4][4]; int l = lower_bound(all(ones), array<int,2>{X[0], 5}) - ones.begin(); int r = upper_bound(all(ones), array<int,2>{5, X[1]}) - ones.begin(); r--; for(int u = l; u <= r; u++) res += min(X[0] - ones[u][0] + 1, X[1] - ones[u][1] + 1); // opt here! ans[X[2]] += X[3] * res; } else{ if(X[0] < 5) ans[X[2]] += X[3] * dp_v[X[0]][X[1]]; else ans[X[2]] += X[3] * dp_ar[X[0]][X[1]]; } } for(int i=1;i<=q;i++) cout << ans[i] << '\n'; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int tc=1;//cin >> tc; while(tc--) _(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...