Submission #894865

#TimeUsernameProblemLanguageResultExecution timeMemory
894865vjudge1Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
2050 ms102980 KiB
// Problem: C - Hedgehog Daniyar and Algorithms // Contest: Virtual Judge - Yosik IOI contest #1 // URL: https://vjudge.net/contest/601761#problem/C // Memory Limit: 256 MB // Time Limit: 3000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define sz(x) (int)x.size() #define all(v) (v).begin(),(v).end() #define rall(v) ((v).rbegin()), ((v).rend()) #define out(v) for(auto& i : v) cout << i << ' '; #define F first #define S second #define int long long const ll N = 1e6 + 400; const ll MOD = 1e9 + 7; const string alf = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int a[N] , b[N] , ans[N] , t[N * 4]; vector < pair <int , pair <int , pair <int ,int > > > > v; void upd(int v, int tl, int tr, int idx ,int val){ if (tl == tr){ t[v] = val; return; } int tm = (tl + tr) / 2; if (idx <= tm){ upd(v * 2, tl , tm , idx , val); } else { upd(v * 2+ 1, tm + 1 , tr, idx ,val); } t[v] = max(t[v * 2] , t[v * 2 + 1]); } int get(int v, int tl , int tr, int l, int r){ if (r < tl || tr < l)return 0; if (l <= tl && tr <= r)return t[v]; int tm = (tl + tr) / 2; return max(get(v * 2, tl , tm , l , r) , get(v * 2 + 1, tm + 1, tr, l , r)); } void solve (){ int n , m; cin >> n >> m; int ok = 1; for(int i = 1; i <= n; i ++){ cin >> a[i]; } for(int i = 1; i <= m; i ++){ int l , r, x; cin >> l >> r >> x; v.pb({r, {l , {x , i}}}); } sort(all(v)); int i = 1; vector <int > cur; for(auto to : v){ int l = to.S.F , r = to.F , k = to.S.S.F , idx = to.S.S.S; int ok = 1; while (i <= r){ while (!cur.empty() && a[cur.back()] <= a[i]){ cur.pop_back(); } if (sz(cur)){ upd(1, 1, n ,cur.back() , a[cur.back()] + a[i]); } cur.pb(i); i ++; } ans[idx] = (get(1, 1, n , l , i) <= k); } for(int i = 1; i <= m; i ++){ cout << ans[i] << endl; } } signed main(){ // freopen("ones.in" , "r" , stdin) ; // freopen("ones.out" , "w" , stdout) ; ios::sync_with_stdio(false); cin.tie(0); int T = 1; // int cs = 1; // cin >>T; while (T --){ // cout <<"Case " << cs ++<< ":" << endl; solve (); // cout <<endl; } }

Compilation message (stderr)

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:68:7: warning: unused variable 'ok' [-Wunused-variable]
   68 |   int ok = 1;
      |       ^~
sortbooks.cpp:54:6: warning: unused variable 'ok' [-Wunused-variable]
   54 |  int ok = 1;
      |      ^~
#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...