제출 #1118861

#제출 시각아이디문제언어결과실행 시간메모리
1118861ZflopHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
2101 ms182872 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],mx_adv[NMAX * 4]; void make(int i,int v,int l,int r,int x) { if (l == r) { mx[x] = v; mx_adv[x] = v; return; } int mid = (l + r) / 2; if (i <= mid) make(i,v,l,mid,2 * x); else make(i,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]; } mx_adv[x] = max(mx_adv[2 * x],mx_adv[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)); } int get_m(int a,int b,int l,int r,int x) { if (a <= l && r <= b) return mx_adv[x]; if (r < a || b < l) return 0; int mid = (l + r) / 2; return max(get_m(a,b,l,mid,2 * x),get_m(a,b,mid + 1,r,2 * x + 1)); } 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); mx[x] = get_m(l,r,1,N,1); 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]; } } 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)); make(i,A[i],1,N,1); } for (int i = 1; i <= M;++i) { cout << ans[i] << '\n'; //cout << i << ' '; } } main() { solve(); }

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

sortbooks.cpp:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | 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...