Submission #412806

#TimeUsernameProblemLanguageResultExecution timeMemory
412806MasterTasterHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
30 / 100
2295 ms43256 KiB
#include <bits/stdc++.h> #define pb push_back #define ll long long #define pii pair<int, int> #define xx first #define yy second #define MAXN 1000010 using namespace std; int n, m, a[MAXN], pom[MAXN], kolko[MAXN]; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin>>n>>m; for (int i=0; i<n; i++) cin>>a[i]; if (n<=5000) { while (m--) { int l, r, k; cin>>l>>r>>k; l--; r--; for (int i=l; i<=r; i++) pom[i-l]=a[i]; vector<int> koji; for (int i=l; i<=r; i++) koji.pb(a[i]); sort(koji.begin(), koji.end()); bool moze=true; for (int i=koji.size()-1; i>0; i--) { int gde=-1; for (int j=i; j>=0; j--) if (pom[j]==koji[i]) { gde=j; break; } for (int j=gde; j<i; j++) { if (pom[j]+pom[j+1]>k) { moze=false; break; } else swap(pom[j], pom[j+1]); } if (!moze) break; } if (!moze) cout<<0<<endl; else cout<<1<<endl; } } else { for (int i=0; i<n; i++) if (a[i-1]<=a[i]) kolko[i]=kolko[i-1]+1; else kolko[i]=1; while (m--) { int l, r, k; cin>>l>>r>>k; l--; r--; if (kolko[r]>=r-l+1) cout<<1<<endl; else cout<<0<<endl; } } }
#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...