#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 = 7e3 + 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], ans[N][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);
}
void output(){
cin >> n >> m;
for(int i = 1; i <= m; i++) cin >> x[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];
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(int j = 1; j <= m; j++) ans[i][x[j]] += get(1LL, 1LL, m, j);
}
for(int i = 1; i <= n; i++){
ll tl = 0, tr = k + 1;
while(tr - tl > 1){
ll tm = ((tl + tr) >> 1);
if(ans[tm][i] >= y[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 |
48 ms |
57940 KB |
Output is correct |
2 |
Correct |
48 ms |
57916 KB |
Output is correct |
3 |
Correct |
50 ms |
57996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
53844 KB |
Output is correct |
2 |
Correct |
44 ms |
51800 KB |
Output is correct |
3 |
Correct |
49 ms |
57940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
83 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
30 ms |
64348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
21084 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
12 ms |
600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |