Submission #498215

#TimeUsernameProblemLanguageResultExecution timeMemory
498215sireanu_vladHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
500 ms91252 KiB
#include <iostream> using namespace std; int n, m, w[1000001], p, a[10001][10001]; void read() { cin >> n >> m; for(int i = 1; i <= n; ++i) cin >> w[i]; } void config() { for(int i = 1; i <= n; ++i) for(int j = i+1; j <= n; ++j) a[i][j] = a[j][i] = w[i] + w[j]; } bool mov(int id, int k, int l, int r) { for(int i = l; i <= r; ++i) { if(i != id && a[i][id] <= k) return 1; } return 0; } bool solve(int l, int r, int k) { int inv = 0; for(int i = l; i < r; ++i) for(int j = i+1; j <= r; ++j) inv += (w[i] > w[j]); if(inv == 0) return 1; for(int i = l; i <= r; ++i) if(w[i] >= k || !mov(i, k, l, r)) return 0; for(int i = l; i <= r; ++i) for(int j = i+1; j <= r; ++j) if(a[i][j] <= k) inv--; return (inv <= 0); } int main() { read(); config(); int l, r, k; while(m--) { cin >> l >> r >> k; cout << solve(l, r, k) << '\n'; } return 0; }
#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...