#include <iostream>
#include <vector>
#include <fstream>
#include <cstring>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <cfloat>
#include <random>
#include <complex>
#include <assert.h>
#include <tuple>
using namespace std;
int n, m;
struct meteor{
int a, b, c;
};
vector<meteor> meteors(300005);
vector<vector<int> > pt(300005);
vector<long long> aim(300005);
int l[300005], r[300005], ans[300005];
vector<vector<int> > g(300005);
long long bit[300005];
void update(int i, long long diff) {
while (i <= m) {
bit[i] += diff;
i += i&-i;
}
}
long long query(int i) {
long long sum = 0;
while (i > 0) {
sum += bit[i];
i -= i&-i;
}
return sum;
}
void rangeupdate(int i, int j, long long diff) {
update(i, diff);
update(j+1, -diff);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n >> m;
for(int i = 1; i <= m; ++i) {
int x; cin >> x;
pt[x].push_back(i);
}
for(int i = 1; i <= n; ++i)
cin >> aim[i];
int q; cin >> q;
for(int i = 1; i <= q; ++i) {
int a, b, c; cin >> a >> b >> c;
meteors[i] = {a, b, c};
}
for(int i = 1; i <= n; ++i) {
l[i] = 1; r[i] = q;
}
while(1) {
memset(bit, 0, sizeof bit);
bool chk = false;
for(int i = 1; i <= n; ++i) {
if(l[i] <= r[i]) {
chk = true;
g[(l[i] + r[i]) / 2].push_back(i);
}
}
if(!chk) break;
for(int i = 1; i <= q; ++i) {
meteor e = meteors[i];
if(e.a > e.b) {
rangeupdate(1, e.b, e.c);
rangeupdate(e.a, m, e.c);
}
else rangeupdate(e.a, e.b, e.c);
for(int h = 0; h < g[i].size(); ++h) {
int j = g[i].back();
g[i].pop_back();
long long amt = 0;
for(int k : pt[j]) {
amt += query(k);
if(amt >= aim[j]) break;
// cout << "k : " << k << " amt : " << amt << endl;
}
// cout << "day : " << i << " contry : " << j << " amt : " << amt << endl;
if(amt >= aim[j]) {
ans[j] = i;
r[j] = i - 1;
} else l[j] = i + 1;
}
}
}
for(int i = 1; i <= n; ++i) {
if(l[i] > q) cout << "NIE" << '\n';
else cout << ans[i] << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |