Submission #332455

#TimeUsernameProblemLanguageResultExecution timeMemory
332455mat_vHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1753 ms86764 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i)) #define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i)) #define mod 998244353 #define xx first #define yy second #define all(a) (a).begin(), (a).end() #define pb push_back #define ll long long #define pii pair<int,int> #define maxn 1000005 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less) mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n,m; int niz[maxn]; int ans[maxn]; struct kveri{ int l; int w; int idx; }; vector<kveri> upit[maxn]; int ri[maxn]; int li[maxn]; int seg[4 * maxn]; void init(int node, int l, int r){ if(l == r){seg[node] = niz[l]; return;} int mid = (l + r) / 2; init(node * 2, l , mid); init(node * 2 + 1, mid + 1, r); seg[node] = max(seg[node * 2], seg[node * 2 + 1]); } int query(int node, int l, int r, int levo, int desno){ if(r < levo || desno < l)return 0; if(l >= levo && r <= desno)return seg[node]; int mid = (l + r) / 2; return max(query(node * 2, l, mid, levo, desno), query(node * 2 + 1, mid + 1, r, levo, desno)); } int seg2[4 * maxn]; void update(int node, int l, int r, int poz, int val){ if(l == r){ seg2[node] = val; return; } int mid = (l + r) / 2; if(poz <= mid)update(node * 2, l, mid, poz, val); else update(node * 2 + 1, mid + 1, r, poz, val); seg2[node] = max(seg2[node * 2], seg2[node * 2 + 1]); } int query2(int node, int l, int r, int levo, int desno){ if(r < levo || desno < l)return 0; if(l >= levo && r <= desno)return seg2[node]; int mid = (l + r) / 2; return max(query2(node * 2, l, mid, levo, desno), query2(node * 2 + 1, mid + 1, r, levo, desno)); } int val[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; ff(i,1,n)cin >> niz[i]; init(1,1,n); ff(i,1,m){ int x,y,z; cin >> x >> y >> z; upit[y].pb({x,z,i}); } stack<pii> s; s.push({niz[1],1}); ff(i,2,n){ if(niz[i] < s.top().xx){ li[i] = s.top().yy; s.push({niz[i],i}); continue; } while(!s.empty() && s.top().xx <= niz[i])s.pop(); if(!s.empty())li[i] = s.top().yy; s.push({niz[i], i}); } ff(i,1,n){ int gde = li[i]; if(gde > 0){ val[gde] = max(val[gde], niz[gde] + niz[i]); update(1,1,n,gde,val[gde]); } for(auto c:upit[i]){ if(query2(1,1,n,c.l,i) <= c.w)ans[c.idx] = 1; } } ff(i,1,m)cout << ans[i] << "\n"; return 0; }

Compilation message (stderr)

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sortbooks.cpp:80:5: note: in expansion of macro 'ff'
   80 |     ff(i,1,n)cin >> niz[i];
      |     ^~
sortbooks.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sortbooks.cpp:82:5: note: in expansion of macro 'ff'
   82 |     ff(i,1,m){
      |     ^~
sortbooks.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sortbooks.cpp:89:5: note: in expansion of macro 'ff'
   89 |     ff(i,2,n){
      |     ^~
sortbooks.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sortbooks.cpp:99:5: note: in expansion of macro 'ff'
   99 |     ff(i,1,n){
      |     ^~
sortbooks.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
sortbooks.cpp:109:5: note: in expansion of macro 'ff'
  109 |     ff(i,1,m)cout << ans[i] << "\n";
      |     ^~
#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...