Submission #1299509

#TimeUsernameProblemLanguageResultExecution timeMemory
1299509InvMODSushi (JOI16_sushi)C++17
100 / 100
1414 ms83564 KiB
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define eb emplace_back #define vi vector<int> #define pi pair<int,int> #define sz(v) (int)(v).size() #define all(v) (v).begin(), (v).end() #define compact(v) (v).erase(unique(all(v)), (v).end()) template<class T> using upq = priority_queue<T, vector<T>, greater<T>>; template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());} template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());} #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define ROF(i, a, b) for(int i = (a); i >= (b); i--) #define sumof(x) accumulate(all(x), 0ll) #define dbg(x) "[" << #x " = " << (x) << "]" #define el "\n" using ll = long long; using ld = long double; template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);} template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);} const int MAX = 4e5 + 5, B = 600; int _N, _Q, a[MAX], idB[MAX]; struct Block{ priority_queue<int> pq; int lB, rB; vector<int> v; Block() {} Block(int lB, int rB, int cB): lB(lB), rB(rB), pq(a + lB, a + rB + 1) { FOR(i, lB, rB) idB[i] = cB; } int build(int l, int r, int x){ // get pass block if(sz(v)){ priority_queue<int, vector<int>, greater<int>> candidate(all(v)); for(int i = lB; i <= rB; i++){ if(a[i] > candidate.top()){ candidate.push(a[i]); a[i] = candidate.top(); candidate.pop(); } } v.clear(); } for(int i = l; i <= r; i++){ if(a[i] > x){ swap(a[i], x); } } pq = priority_queue<int>(a + lB, a + rB + 1); return x; } int update(int x){ int ans = x; if(sz(pq) && x < pq.top()){ ans = pq.top(); pq.pop(); pq.push(x), v.eb(x); } return ans; } }; vector<Block> b; void update(int L, int R, int &P){ int blockL = (L - 1) / B + 1; int blockR = (R + B - 1) / B; if(blockL == blockR){ P = b[blockL].build(L, R, P); } else{ P = b[blockL].build(L, min(_N, blockL * B), P); FOR(i, blockL + 1, blockR - 1){ P = b[i].update(P); } P = b[blockR].build((blockR - 1) * B + 1, R, P); } } void Main() { cin >> _N >> _Q; int nblock = (_N + B - 1) / B; FOR(i, 1, _N) cin >> a[i]; b = vector<Block>(nblock + 1); FOR(i, 1, nblock){ int lblock = (i - 1) * B + 1; int rblock = min(_N, i * B); b[i] = Block(lblock, rblock, i); } FOR(i, 1, _Q){ int S, T, P; cin >> S >> T >> P; if(S > T){ update(S, _N, P); update(1, T, P); } else update(S, T, P); cout << P << el; } } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define name "InvMOD" if(fopen(name".INP", "r")){ freopen(name".INP", "r", stdin); freopen(name".OUT", "w", stdout); } int t = 1; while(t--) Main(); return 0; }

Compilation message (stderr)

sushi.cpp: In function 'int32_t main()':
sushi.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sushi.cpp:130:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...