# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
964707 |
2024-04-17T11:38:00 Z |
BhavayGoyal |
Meteors (POI11_met) |
C++14 |
|
736 ms |
34880 KB |
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"
const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// -------------------------------------------------- Main Code --------------------------------------------------
struct bit {
int n;
vi tree;
bit(int N) {n = N+5; tree = vi(n+2);}
void update(int idx, int val) {idx++; for (idx; idx <= n; idx += (idx&-idx)) tree[idx] += val;}
int sum(int idx) {idx++; int ans = 0; for (idx; idx; idx -= (idx&-idx)) ans += tree[idx]; return ans;}
int query(int l, int r) {return sum(r)-sum(l-1);}
};
struct state { int l, r; };
const int N = 3e5+5;
int req[N], ans[N];
vi positions[N];
void sol() {
int n, m; cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x; cin >> x;
positions[x].pb(i);
}
for (int i = 1; i <= n; i++) cin >> req[i];
int q; cin >> q;
array<int, 3> queries[q+1];
for (int i = 1; i <= q; i++) {
int a, b, c; cin >> a >> b >> c;
queries[i] = {a, b, c};
}
state currState[n+1];
for (int i = 1; i <= n; i++) currState[i] = {1, q};
for (int temp = 0; temp <= 20; temp++) {
vector<int> query[q+1];
for (int i = 1; i <= n; i++) {
if (currState[i].l > currState[i].r) continue;
query[(currState[i].l+currState[i].r)/2].push_back(i);
}
bit tree(m);
for (int i = 1; i <= q; i++) {
int l = queries[i][0], r = queries[i][1], val = queries[i][2];
if (l > r) {
swap(l, r);
tree.update(r, val);
tree.update(m+1, -val);
tree.update(1, val);
tree.update(l+1, -val);
}
else {
tree.update(l, val);
tree.update(r+1, -val);
}
for (auto j : query[i]) {
int ct = 0;
for (auto x : positions[j]) {
ct += tree.sum(x);
}
int &l = currState[j].l, &r = currState[j].r, mid = (l+r)/2;
if (ct >= req[j]) r = mid-1, ans[j] = mid;
else l = mid+1;
}
}
}
for (int i = 1; i <= n; i++) {
if (ans[i] == 0) cout << "NIE" << endl;
else cout << ans[i] << endl;
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin >> t;
while (t--) {
sol();
}
return 0;
}
Compilation message
met.cpp: In member function 'void bit::update(int, int)':
met.cpp:40:48: warning: statement has no effect [-Wunused-value]
40 | void update(int idx, int val) {idx++; for (idx; idx <= n; idx += (idx&-idx)) tree[idx] += val;}
| ^~~
met.cpp: In member function 'int bit::sum(int)':
met.cpp:41:48: warning: statement has no effect [-Wunused-value]
41 | int sum(int idx) {idx++; int ans = 0; for (idx; idx; idx -= (idx&-idx)) ans += tree[idx]; return ans;}
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8792 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
3 ms |
8864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8796 KB |
Output is correct |
2 |
Correct |
3 ms |
8796 KB |
Output is correct |
3 |
Correct |
4 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
60 ms |
12056 KB |
Output is correct |
2 |
Correct |
98 ms |
13152 KB |
Output is correct |
3 |
Correct |
88 ms |
12828 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
81 ms |
12488 KB |
Output is correct |
2 |
Correct |
88 ms |
12664 KB |
Output is correct |
3 |
Correct |
90 ms |
13148 KB |
Output is correct |
4 |
Correct |
24 ms |
10504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
12124 KB |
Output is correct |
2 |
Correct |
80 ms |
13276 KB |
Output is correct |
3 |
Correct |
43 ms |
11096 KB |
Output is correct |
4 |
Correct |
87 ms |
12960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
12132 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
736 ms |
34880 KB |
Output is correct |
2 |
Incorrect |
450 ms |
29660 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
694 ms |
34056 KB |
Output is correct |
2 |
Incorrect |
518 ms |
28128 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |