# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
853389 |
2023-09-24T09:16:54 Z |
overwatch9 |
Meteors (POI11_met) |
C++17 |
|
6000 ms |
65536 KB |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
using ull = unsigned long long;
struct stree {
#define lc v*2
#define rc v*2+1
vector <ull> tree;
stree() {}
stree (int s) {
tree.resize(4*s);
}
void pushdown(int v) {
// since we're doing point query, we don't need to maintain
// a separate pd variable
if (tree[v] == 0)
return;
tree[lc] += tree[v];
tree[rc] += tree[v];
tree[v] = 0;
}
void update(int v, int tl, int tr, int l, int r, ull val) {
if (tl > r || tr < l)
return;
if (tl >= l && tr <= r) {
tree[v] += val;
return;
}
pushdown(v);
int tm = (tl + tr) / 2;
update(lc, tl, tm, l, r, val);
update(rc, tm+1, tr, l, r, val);
}
ull query(int v, int tl, int tr, int p) {
if (tl > p || tr < p)
return 0;
if (tl == tr)
return tree[v];
pushdown(v);
int tm = (tl + tr) / 2;
return max(query(lc, tl, tm, p), query(rc, tm+1, tr, p));
}
};
const int maxnmk = 3 * 1e5 + 1;
int n, m, k;
int owners[maxnmk], req[maxnmk], ans[maxnmk];
pair <pair <int, int>, ull> updates[maxnmk];
queue <pair <int, int>> q;
vector <vector <int>> subsets, stations;
int prev_mid = -1;
stree tree;
void search(int lo, int hi) {
int mid = (lo + hi) / 2;
if (prev_mid < mid) {
for (int i = prev_mid+1; i <= mid; i++) {
int l = updates[i].first.first;
int r = updates[i].first.second;
ull val = updates[i].second;
if (l <= r)
tree.update(1, 0, m, l, r, val);
else {
tree.update(1, 0, m, l, m-1, val);
tree.update(1, 0, m, 0, r, val);
}
}
} else {
for (int i = mid+1; i <= prev_mid; i++) {
int l = updates[i].first.first;
int r = updates[i].first.second;
ull val = updates[i].second;
if (l <= r)
tree.update(1, 0, m, l, r, -val);
else {
tree.update(1, 0, m, l, m-1, -val);
tree.update(1, 0, m, 0, r, -val);
}
}
}
// check if any members have met their requirements
bool added_lo = false, added_hi = false;
for (auto i : subsets[mid]) {
ull tot = 0;
for (auto j : stations[i])
tot += tree.query(1, 0, m, j);
if (tot >= req[i]) {
if (ans[i] == -1)
ans[i] = mid;
else
ans[i] = min(ans[i], mid);
if (lo != mid) {
added_lo = true;
subsets[(lo + mid) / 2].push_back(i);
}
} else {
if (mid != hi) {
added_hi = true;
subsets[(mid+1 + hi) / 2].push_back(i);
}
}
}
if (added_lo)
q.push({lo, mid});
if (added_hi)
q.push({mid+1, hi});
prev_mid = mid;
}
int main() {
cin >> n >> m;
fill(ans, ans + n, -1);
stations.resize(n);
for (int i = 0; i < m; i++) {
cin >> owners[i];
owners[i]--;
stations[owners[i]].push_back(i);
}
for (int i = 0; i < n; i++)
cin >> req[i];
cin >> k;
for (int i = 0; i < k; i++) {
int l, r;
ull val;
cin >> l >> r >> val;
l--; r--;
updates[i].first.first = l;
updates[i].first.second = r;
updates[i].second = val;
}
q.push({0, k-1});
subsets.resize(k);
for (int i = 0; i < n; i++)
subsets[(k-1)/2].push_back(i);
tree = stree(m+1);
while (!q.empty()) {
int l = q.front().first;
int r = q.front().second;
q.pop();
search(l, r);
}
for (int i = 0; i < n; i++) {
if (ans[i] == -1)
cout << "NIE\n";
else
cout << ans[i]+1 << '\n';
}
}
Compilation message
met.cpp: In function 'void search(int, int)':
met.cpp:90:17: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
90 | if (tot >= req[i]) {
| ~~~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2392 KB |
Output is correct |
3 |
Correct |
6 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2392 KB |
Output is correct |
2 |
Correct |
5 ms |
2392 KB |
Output is correct |
3 |
Correct |
6 ms |
2652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
486 ms |
8272 KB |
Output is correct |
2 |
Correct |
639 ms |
11856 KB |
Output is correct |
3 |
Correct |
597 ms |
11304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
566 ms |
9552 KB |
Output is correct |
2 |
Correct |
587 ms |
10612 KB |
Output is correct |
3 |
Correct |
675 ms |
12112 KB |
Output is correct |
4 |
Correct |
119 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
253 ms |
8804 KB |
Output is correct |
2 |
Correct |
365 ms |
12624 KB |
Output is correct |
3 |
Correct |
112 ms |
6480 KB |
Output is correct |
4 |
Correct |
551 ms |
11644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
238 ms |
7952 KB |
Output is correct |
2 |
Correct |
558 ms |
10716 KB |
Output is correct |
3 |
Correct |
384 ms |
9216 KB |
Output is correct |
4 |
Correct |
635 ms |
13392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1851 ms |
39196 KB |
Output is correct |
2 |
Correct |
850 ms |
33496 KB |
Output is correct |
3 |
Correct |
934 ms |
15336 KB |
Output is correct |
4 |
Execution timed out |
6096 ms |
65536 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1850 ms |
37992 KB |
Output is correct |
2 |
Correct |
1365 ms |
32208 KB |
Output is correct |
3 |
Correct |
154 ms |
15080 KB |
Output is correct |
4 |
Execution timed out |
6048 ms |
65536 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |