#include <bits/stdc++.h>
#define ll long long
#define Sayan ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define Int(a,x) a+1 , a+1+x
#define sz() size()
#define F first
#define S second
#define pb push_back
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define pii pair<ll,ll>
using namespace std ;
const ll N = 2e5+5;
const ll INF = 1e18;
const ll mod = 1e9+7;
/*
ll binpow(ll a , ll b){
if(b == 0) return 1;
if(b%2) return binpow(a , b-1) * a % mod;
ll c = binpow(a , b/2) % mod;
return c*c%mod;
}
*/
ll a[N],coun[N];
ll t[N*4];
ll sum[N],lz[N];
ll k=400;
ll otv[N];
ll gl[N],gr[N],x[N];
void upd(ll l,ll r,ll val){
for(;l<=r;){
if(l%k==0 && l+k-1<=r){
lz[l/k]+=val;
l+=k;
}
else {
sum[l]+=val;
l++;
}
}
}
void solve(){
ll n,m;
cin>>n>>m;
for(ll i=1;i<=m;i++){
cin>>a[i];
}
for(ll i=1;i<=n;i++){
cin>>coun[i];
}
ll q;
cin>>q;
for(ll i=1;i<=q;i++){
cin>>gl[i]>>gr[i]>>x[i];
}
for(ll i=1;i<=n;i++){
ll l=1,r=q,res=0,posl=0;
while(l<=r){
for(ll j=1;j<=m;j++){
otv[a[j]]=0;
sum[j]=0;
lz[j/k]=0;
}
ll md=(l+r)/2;
for(ll j=1;j<=md;j++){
if(gl[j]>gr[j]){
upd(gl[j],m,x[j]);
upd(1,gr[j],x[j]);
}
else {
upd(gl[j],gr[j],x[j]);
}
}
for(ll j=1;j<=m;j++){
otv[a[j]]+=sum[j];
otv[a[j]]+=lz[j/k];
}
if(coun[i]>otv[i]){
l=md+1;
}
else {
r=md-1;
res=md;
// cout<<md<<" "<<coun[i]<<" "<<otv[i]<<"\n";
}
}
// cout<<l<<" "<<r<<"\n";
if(res==0)cout<<"NIE\n";
else cout<<res<<"\n";
}
}
signed main () {
Sayan;
ll t=1;
//cin>>t;
while(t--)solve();
}
Compilation message
met.cpp: In function 'void solve()':
met.cpp:61:20: warning: unused variable 'posl' [-Wunused-variable]
61 | ll l=1,r=q,res=0,posl=0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
856 ms |
12884 KB |
Output is correct |
2 |
Execution timed out |
6055 ms |
12636 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1325 ms |
12760 KB |
Output is correct |
2 |
Correct |
780 ms |
12756 KB |
Output is correct |
3 |
Execution timed out |
6034 ms |
12636 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6060 ms |
12888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6063 ms |
12892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6091 ms |
12888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6104 ms |
12888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
4956 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
13 ms |
4952 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |