#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (b); i >= (a); i --)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPD(i, n) for (int i = (n) - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
Phu Trong from Nguyen Tat Thanh High School for gifted student
*/
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
#define MAX 500005
int N, M, numQuery;
int target[MAX];
vector<int> station[MAX];
int L[MAX], R[MAX], G[MAX];
int ans[MAX];
int F[MAX];
void upd(int p, int val){
for (; p <= M; p += p & (-p)) F[p] += val;
}
void upd(int l, int r, int v) {
upd(r + 1, -v), upd(l, v);
if (l > r)
upd(1, v), upd(M + 1, -v);
}
int query(int p){
int res = 0;
for (; p > 0; p -= p & (-p)) res += F[p];
return res;
}
void parallel(int l, int r, vector<int>&cand){
if (l + 1 == r || cand.empty()){
for (int&i : cand) ans[i] = l;
return;
}
int m = (l + r) >> 1;
for (int i = l; i < m; ++i){
upd(L[i], R[i], G[i]);
}
vector<int> ok, not_ok;
for (int &i : cand){
int sum = 0;
bool ahihi = 0;
for (int &pos : station[i]){
sum += query(pos);
if (sum >= target[i]) {
ahihi = 1;
}
}
if (ahihi) ok.push_back(i);
else {
target[i] -= sum;
not_ok.push_back(i);
}
}
for (int i = l; i < m; ++i){
upd(L[i], R[i], -G[i]);
}
parallel(l, m, ok);
parallel(m, r, not_ok);
}
void process(void){
cin >> N >> M;
for (int i = 1; i <= M; ++i){
int x; cin >> x;
station[x].emplace_back(i);
}
for (int i = 1; i <= N; ++i) cin >> target[i];
cin >> numQuery;
for (int i = 0; i < numQuery; ++i){
cin >> L[i] >> R[i] >> G[i];
}
vector<int> cand;
for (int i = 1; i <= M; ++i) cand.push_back(i);
parallel(0, numQuery + 1, cand);
for (int i = 1; i <= N; ++i){
if(ans[i] == numQuery) cout << "NIE\n";
else cout << ans[i] + 1 << '\n';
}
}
signed main(){
#define name "Whisper"
cin.tie(nullptr) -> sync_with_stdio(false);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
process();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12380 KB |
Output is correct |
2 |
Correct |
5 ms |
12200 KB |
Output is correct |
3 |
Correct |
5 ms |
12380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12376 KB |
Output is correct |
2 |
Correct |
5 ms |
12392 KB |
Output is correct |
3 |
Correct |
7 ms |
12376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
21788 KB |
Output is correct |
2 |
Correct |
67 ms |
22160 KB |
Output is correct |
3 |
Correct |
66 ms |
21100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
21460 KB |
Output is correct |
2 |
Correct |
72 ms |
21452 KB |
Output is correct |
3 |
Correct |
50 ms |
19884 KB |
Output is correct |
4 |
Correct |
23 ms |
19664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
53 ms |
21572 KB |
Output is correct |
2 |
Correct |
62 ms |
21452 KB |
Output is correct |
3 |
Correct |
17 ms |
13404 KB |
Output is correct |
4 |
Correct |
64 ms |
20844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
21832 KB |
Output is correct |
2 |
Correct |
72 ms |
21392 KB |
Output is correct |
3 |
Correct |
43 ms |
21644 KB |
Output is correct |
4 |
Correct |
78 ms |
20600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
387 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
377 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |