Submission #173415

#TimeUsernameProblemLanguageResultExecution timeMemory
173415TricksterHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
3070 ms258696 KiB
#include <algorithm> #include <iostream> #include <stdio.h> #include <vector> #include <queue> #include <cmath> #include <set> #include <map> #define N 1000010 #define ff first #define ss second #define ll long long #define pb push_back #define mod 1000000007 #define pii pair <int, int> using namespace std; int n, q; int v[N]; pii T[N*4]; int l, r, x; vector <int> E[N*4]; void uni(int CEP, int SAG, int node) { pii ans = {0, 0}; vector <int> res; int pos = 0, pos2 = 0; while(pos < E[CEP].size() && pos2 < E[SAG].size()) { if(E[CEP][pos] < E[SAG][pos2]) res.pb(E[CEP][pos++]); else res.pb(E[SAG][pos2++]); } int a = pos2-1; while(pos < E[CEP].size()) res.pb(E[CEP][pos++]); while(pos2 < E[SAG].size()) res.pb(E[SAG][pos2++]); if(T[CEP].ss == 0 || T[SAG].ss == 0) { ans = (T[CEP].ss == 0 ? T[SAG] : T[CEP]); } else { if(T[CEP].ff + T[CEP].ss >= T[SAG].ff + T[SAG].ss) ans = T[CEP]; else ans = T[SAG]; } if(a != -1) { int x = E[SAG][a]; if(ans.ss == 0 || ans.ff + ans.ss < E[CEP].back() + x) ans = {E[CEP].back(), x}; } T[node] = ans; E[node].clear(); for(auto i: res) E[node].pb(i); } void build(int l, int r, int node) { if(l == r) { T[node] = {v[l], 0}; E[node].pb(v[l]); return; } build(l, (l+r)/2, node*2); build((l+r)/2+1, r, node*2+1); uni(node*2, node*2+1, node); } void tap(int a, int b, int l, int r, int node) { if(l > b || r < a) return; if(l >= a && r <= b) { uni(0, node, 0); return; } tap(a, b, l, (l+r)/2, node*2); tap(a, b, (l+r)/2+1, r, node*2+1); } int main() { cin >> n >> q; for(int i = 1; i <= n; i++) cin >> v[i]; build(1, n, 1); for(int i = 1; i <= q; i++) { cin >> l >> r >> x; E[0].clear(); T[0] = {0, 0}; tap(l, r, 1, n, 1); if(T[0].ss == 0 || T[0].ff + T[0].ss <= x) cout << "1\n"; else cout << "0\n"; } }

Compilation message (stderr)

sortbooks.cpp: In function 'void uni(int, int, int)':
sortbooks.cpp:32:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size() && pos2 < E[SAG].size()) {
        ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:32:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size() && pos2 < E[SAG].size()) {
                               ~~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:40:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos < E[CEP].size()) res.pb(E[CEP][pos++]);
        ~~~~^~~~~~~~~~~~~~~
sortbooks.cpp:41:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(pos2 < E[SAG].size()) res.pb(E[SAG][pos2++]);
        ~~~~~^~~~~~~~~~~~~~~
#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...