// KCPC - 50.6907
#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 md(l, r) ((l + r) >> 1)
#define rv(x) ((x << 1) + 1)
#define lv(x) (x << 1)
#define pb emplace_back
#define elif else if
#define uns unsigned
#define emp empty()
#define nll nullptr
#define S second
#define F first
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef vector < ll > vll;
typedef vector < int > vi;
typedef pair < ll, ll > pll;
typedef pair < int, int > pi;
typedef pair < ldb, ldb > pldb;
typedef vector < pair < ll, ll > > vpll;
typedef vector < pair < int, int > > vpi;
const int N = 3e5 + 3;
const int M = 1e4 + 123;
const int mod = 1e9 + 7;
const int mxlg = 19;
const int K = 20;
const int P = 31;
const ll inf = 1e9 + 10;
//mt19937 rnd(07062006);
int n, m, q;
ll s;
int a[N], b[N], l[N], r[N], x[N];
int al[N], ar[N];
ll t[4 * N];
vi v[N], vq[N];
void upd(ll tl, ll tr, ll x, ll v = 1, ll l = 1, ll r = m){
if(r < tl || tr < l) return;
if(tl <= l && r <= tr){
t[v] += x;
return;
}
ll m = md(l, r);
upd(tl, tr, x, lv(v), l, m);
upd(tl, tr, x, rv(v), m + 1, r);
}
ll get(ll k, ll v = 1, ll l = 1, ll r = m){
if(l == r) return t[v];
ll m = md(l, r);
if(k <= m) return get(k, lv(v), l, m) + t[v];
else return get(k, rv(v), m + 1, r) + t[v];
}
void output(){
cin >> n >> m;
for(int i = 1; i <= m; i++) cin >> b[i], v[b[i]].pb(i);
for(int i = 1; i <= n; i++) cin >> a[i];
cin >> q;
for(int i = 1; i <= n; i++){
al[i] = 1;
ar[i] = q + 1;
}
for(int i = 1; i <= q; i++) cin >> l[i] >> r[i] >> x[i];
bool ok = 1;
while(ok){
ok = 0;
memset(t, 0, sizeof(t));
for(int i = 1; i <= n; i++)
if(al[i] != ar[i])
vq[md(al[i], ar[i])].pb(i);
for(int i = 1; i <= q; i++){
if(l[i] <= r[i]) upd(l[i], r[i], x[i]);
else upd(l[i], m, x[i]), upd(1, r[i], x[i]);
for(auto id : vq[i]){
ok = 1, s = 0;
for(auto x : v[id]){
s += get(x);
if(s >= a[id]) break;
}
if(s >= a[id]) ar[id] = i;
else al[id] = i + 1;
}
vq[i].clear();
}
}
for(int i = 1; i <= n; i++){
if(al[i] == q + 1) cout << "NIE\n";
else cout << al[i] << '\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 |
10 ms |
31320 KB |
Output is correct |
2 |
Correct |
10 ms |
31320 KB |
Output is correct |
3 |
Correct |
10 ms |
31324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
31324 KB |
Output is correct |
2 |
Correct |
9 ms |
31324 KB |
Output is correct |
3 |
Correct |
11 ms |
31460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
32100 KB |
Output is correct |
2 |
Correct |
313 ms |
33804 KB |
Output is correct |
3 |
Correct |
309 ms |
33664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
279 ms |
33104 KB |
Output is correct |
2 |
Correct |
289 ms |
33104 KB |
Output is correct |
3 |
Correct |
298 ms |
33868 KB |
Output is correct |
4 |
Correct |
67 ms |
32908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
140 ms |
32552 KB |
Output is correct |
2 |
Correct |
187 ms |
34292 KB |
Output is correct |
3 |
Correct |
135 ms |
31572 KB |
Output is correct |
4 |
Correct |
294 ms |
33880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
31732 KB |
Output is correct |
2 |
Correct |
242 ms |
33108 KB |
Output is correct |
3 |
Correct |
262 ms |
31828 KB |
Output is correct |
4 |
Correct |
309 ms |
35056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2625 ms |
43628 KB |
Output is correct |
2 |
Correct |
925 ms |
32708 KB |
Output is correct |
3 |
Correct |
715 ms |
31556 KB |
Output is correct |
4 |
Correct |
3457 ms |
65536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2565 ms |
42808 KB |
Output is correct |
2 |
Correct |
780 ms |
32700 KB |
Output is correct |
3 |
Correct |
554 ms |
31444 KB |
Output is correct |
4 |
Runtime error |
3282 ms |
65536 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |