# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
660348 |
2022-11-21T17:20:11 Z |
emuyumi |
Meteors (POI11_met) |
C++17 |
|
1130 ms |
25948 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Fenwick{
vector<ll> a;
vector<int> t;
int T;
Fenwick(int N) : T(0), a(N), t(N) {}
void ins(int i, ll v){
for (++i; i < a.size(); i += i & -i){
if (t[i] != T) a[i] = 0;
if (a[i] <= 1e12) a[i] += v;
t[i] = T;
}
}
ll qry(int i){
ll ret = 0;
for (++i; i; i -= i & -i){
if (t[i] == T) ret += a[i];
}
return ret;
}
void reset(){ T++; }
};
int main(){
cin.tie(0)->sync_with_stdio(0);
int N, M; cin >> N >> M;
vector<int> o(M);
vector<vector<int>> own(N);
for (int i = 0; i < M; ++i){
cin >> o[i]; o[i]--;
own[o[i]].push_back(i);
}
vector<ll> need(N);
for (int i = 0; i < N; ++i){
cin >> need[i];
}
struct Meteor{ int l, r, a; };
int Q; cin >> Q;
vector<Meteor> qs(Q);
for (int i = 0; i < Q; ++i){
cin >> qs[i].l >> qs[i].r >> qs[i].a;
qs[i].l--, qs[i].r--;
}
vector<int> ans(N);
Fenwick bit(M + 10);
auto go = [&](auto self, int ql, int qr, vector<int> states) -> void{
if (qr == ql+1){
auto [l, r, a] = qs[ql];
for (int i : states){
ll cur = 0;
for (int j : own[i]){
if (l > r){
if (j <= r|| j >= l){
cur += a;
}
}
else{
if (l <= j && j <= r){
cur += a;
}
}
}
if (need[i] <= cur){
ans[i] = ql;
need[i] = 0;
}
else ans[i] = -1;
}
return;
}
int mid = (ql+qr) >> 1;
bit.reset();
for (int i = ql; i < mid; ++i){
auto [l, r, a] = qs[i];
if (l > r){
bit.ins(0, a);
bit.ins(r+1, -a);
bit.ins(l, a);
bit.ins(M, -a);
}
else{
bit.ins(l, a);
bit.ins(r+1, -a);
}
}
vector<int> vl, vr;
for (int i : states){
ll cur = 0;
for (int j : own[i]){
cur += bit.qry(j);
}
if (cur >= need[i]){
vl.push_back(i);
}
else{
need[i] -= cur;
vr.push_back(i);
}
}
self(self, ql, mid, vl);
self(self, mid, qr, vr);
};
vector<int> all_states(N);
iota(all_states.begin(), all_states.end(), 0);
go(go, 0, Q, all_states);
// for (int i = 0; i < Q; ++i){
// cout << need[i] << " ";
// }
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 constructor 'Fenwick::Fenwick(int)':
met.cpp:9:9: warning: 'Fenwick::T' will be initialized after [-Wreorder]
9 | int T;
| ^
met.cpp:7:16: warning: 'std::vector<long long int> Fenwick::a' [-Wreorder]
7 | vector<ll> a;
| ^
met.cpp:10:5: warning: when initialized here [-Wreorder]
10 | Fenwick(int N) : T(0), a(N), t(N) {}
| ^~~~~~~
met.cpp: In member function 'void Fenwick::ins(int, ll)':
met.cpp:12:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for (++i; i < a.size(); i += i & -i){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
2784 KB |
Output is correct |
2 |
Correct |
123 ms |
6636 KB |
Output is correct |
3 |
Correct |
106 ms |
3120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
2844 KB |
Output is correct |
2 |
Correct |
98 ms |
2688 KB |
Output is correct |
3 |
Correct |
124 ms |
5208 KB |
Output is correct |
4 |
Correct |
27 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
2508 KB |
Output is correct |
2 |
Correct |
94 ms |
5852 KB |
Output is correct |
3 |
Correct |
32 ms |
980 KB |
Output is correct |
4 |
Correct |
90 ms |
3364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
2004 KB |
Output is correct |
2 |
Correct |
105 ms |
2884 KB |
Output is correct |
3 |
Correct |
66 ms |
2108 KB |
Output is correct |
4 |
Correct |
121 ms |
4644 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1130 ms |
25948 KB |
Output is correct |
2 |
Incorrect |
761 ms |
9848 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1082 ms |
22208 KB |
Output is correct |
2 |
Incorrect |
787 ms |
9940 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |