#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 600005;
int n, m, a[nmax], k, p[nmax], x[nmax], y[nmax], z[nmax];
int tz[nmax];
void add(int l, int r, int val){
tz[l] += val;
tz[r + 1] -= val;
}
int32_t main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
//freopen("input.in", "r", stdin);
cin >> n >> m;
for(int i=1;i<=m;i++){
cin >> a[i];
}
for(int i=1;i<=n;i++){
cin >> p[i];
}
cin >> k;
for(int i=1;i<=k;i++){
cin >> x[i] >> y[i] >> z[i];
}
vector<int>ans;
for(int i=1;i<=n;i++){
int l = 1, r = k, ok = 0;
while(l <= r){
int mid = l + (r - l) / 2;
for(int j=1;j<=mid;j++){
if(x[j] > y[j]){
add(x[j], m, z[j]);
add(1, y[j], z[j]);
}
else{
add(x[j], y[j], z[j]);
}
}
int curr = 0, strans = 0;
for(int j=1;j<=m;j++){
curr += tz[j];
if(a[j] == i){
strans += curr;
}
}
for(int j=1;j<=m+1;j++) tz[j] = 0;
if(strans >= p[i]){
ok = mid;
r = mid - 1;
}
else{
l = mid + 1;
}
}
ans.push_back(ok);
}
for(auto it : ans){
if(!it) cout << "NIE" << '\n';
else{
cout << it << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
328 KB |
Output is correct |
2 |
Correct |
19 ms |
340 KB |
Output is correct |
3 |
Correct |
7 ms |
416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
340 KB |
Output is correct |
2 |
Correct |
6 ms |
408 KB |
Output is correct |
3 |
Correct |
23 ms |
420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6082 ms |
3212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6043 ms |
3588 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6047 ms |
3404 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
636 ms |
3408 KB |
Output is correct |
2 |
Execution timed out |
6054 ms |
3712 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6077 ms |
20720 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6007 ms |
20496 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |