#pragma GCC optimize("inline")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("03")
#include <bits/stdc++.h>
#define file(s) freopen(s".in", "r", stdin); freopen(s".out", "w", stdout);
#define adiyer(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define eb emplace_back
#define elif else if
#define uns unsigned
#define emp empty()
#define S second
#define F first
#define int long long
using namespace std;
typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < pair < ll, ll > > vpll;
typedef vector < pair < int, int > > vpii;
const int N = 3e5 + 123;
const int mod = 1e9 + 7;
const int mxlg = 30;
const int P = 31;
const int K = 599;
const ll inf = 1e9 + 10;
ll n, m, k;
ll x[N], y[N], a[N], l[N], r[N], t[4 * N], z[4 * N];
vector < ll > ans[N];
void push(ll v, ll l, ll r){
if(z[v] == 0) return;
if(l != r){
z[(v << 1)] += z[v];
z[(v << 1) + 1] += z[v];
}
t[v] += z[v] * (r - l + 1);
z[v] = 0;
}
void upd(ll v, ll l, ll r, ll tl, ll tr, ll x){
push(v, l, r);
if(tr < l || r < tl) return;
if(tl <= l && r <= tr){
z[v] += x;
push(v, l, r);
return;
}
ll m = ((l + r) >> 1);
upd((v << 1), l, m, tl, tr, x);
upd((v << 1) + 1, m + 1, r, tl, tr, x);
t[v] = t[(v << 1)] + t[(v << 1) + 1];
}
ll get(ll v, ll l, ll r, ll pos){
push(v, l, r);
if(l == r) return t[v];
ll m = ((l + r) >> 1);
if(pos <= m) return get((v << 1), l, m, pos);
else return get((v << 1) + 1, m + 1, r, pos);
}
bool f(ll tm, ll cur){
ll res = 0;
for(int i = 1; i <= tm; i++){
if(l[i] <= r[i]){
upd(1LL, 1LL, m, l[i], r[i], a[i]);
}
else{
upd(1LL, 1LL, m, l[i], m, a[i]);
upd(1LL, 1LL, m, 1LL, r[i], a[i]);
}
}
for(auto it : ans[cur]) res += get(1LL, 1LL, m, it);
for(int i = 1; i <= tm; i++){
if(l[i] <= r[i]){
upd(1LL, 1LL, m, l[i], r[i], -a[i]);
}
else{
upd(1LL, 1LL, m, l[i], m, -a[i]);
upd(1LL, 1LL, m, 1LL, r[i], -a[i]);
}
}
return res >= y[cur];
}
void output(){
cin >> n >> m;
for(int i = 1; i <= m; i++) cin >> x[i], ans[x[i]].eb(i);
for(int i = 1; i <= n; i++) cin >> y[i];
cin >> k;
for(int i = 1; i <= k; i++) cin >> l[i] >> r[i] >> a[i];
for(int i = 1; i <= n; i++){
ll tl = 0, tr = k + 1;
while(tr - tl > 1){
ll tm = ((tl + tr) >> 1);
if(f(tm, i)) tr = tm;
else tl = tm;
}
if(tr == k + 1) cout << "NIE\n";
else cout << tr << '\n';
}
}
const bool cases = 0;
signed main(){
// file("disrupt");
adiyer();
int tt = 1;
if(cases) cin >> tt;
for(int i = 1; i <= tt; i++){
// cout << "Case " << i << ":\n";
output();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
358 ms |
21152 KB |
Output is correct |
2 |
Correct |
2075 ms |
21148 KB |
Output is correct |
3 |
Correct |
519 ms |
21084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
21332 KB |
Output is correct |
2 |
Correct |
190 ms |
21336 KB |
Output is correct |
3 |
Correct |
2299 ms |
21156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6024 ms |
23640 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6014 ms |
23644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6050 ms |
23900 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6007 ms |
23508 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6054 ms |
42068 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6058 ms |
43064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |