제출 #1118853

#제출 시각아이디문제언어결과실행 시간메모리
1118853ZflopHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
1780 ms161868 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int NMAX = (int)1e6 + 50; vector<vector<int>>L[NMAX]; int N,M,A[NMAX],ans[NMAX],add[NMAX * 4],mx[NMAX * 4]; void update(int a,int b,int v,int l,int r,int x) { if (a <= l && r <= b) { add[x] = max(add[x],v); return; } if (r < a || b < l) return; int mid = (l + r) / 2; update(a,b,v,l,mid,2 * x); update(a,b,v,mid + 1,r,2 * x + 1); if (mx[2 * x] + add[2 * x] > mx[2 * x + 1] + add[2 * x + 1]) { mx[x] = mx[2 * x]; add[x] = add[2 * x]; } else { mx[x] = mx[2 * x + 1]; add[x] = add[2 * x + 1]; } } int get_maxim(int a,int b,int l,int r,int x) { if (a <= l && r <= b) return add[x] + mx[x]; if (r < a || b < l) return 0; int mid = (l + r) / 2; return max(get_maxim(a,b,l,mid,2 * x),get_maxim(a,b,mid + 1,r,2 * x + 1)); } void solve() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 1; i <= N;++i) cin >> A[i]; for (int i = 1; i <= M;++i) { int l,r,k; cin >> l >> r >> k; L[l].push_back({r,k,i}); } A[N + 1] = (int)1e9 * 2; stack<int>q; q.push(N + 1); for (int i = N; i;--i) { while (A[i] > A[q.top()]) q.pop(); int j = q.top() - 1; q.push(i); update(i + 1,j,A[i],1,N,1); for (auto X : L[i]) ans[X[2]] = (X[1] >= get_maxim(i,X[0],1,N,1)); } for (int i = 1; i <= M;++i) { cout << ans[i] << '\n'; //cout << i << ' '; } } main() { solve(); }

컴파일 시 표준 에러 (stderr) 메시지

sortbooks.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | main() {
      | ^~~~
#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...