#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 = 3e5+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 k=440;
ll otv[N];
ll gl[N],gr[N],x[N];
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=-1,posl=0;
while(l<=r){
ll md=(l+r)/2;
for(ll j=1;j<=m;j++){
otv[j]=0;
}
for(ll j=1;j<=md;j++){
if(gl[j]>gr[j]){
for(ll g=gl[j];g<=m;g++){
otv[a[g]]+=x[j];
}
for(ll g=1;g<=gr[j];g++){
otv[a[g]]+=x[j];
}
}
else {
for(ll g=gl[j];g<=gr[j];g++){
otv[a[g]]+=x[j];
}
}
}
if(coun[i]>otv[i]){
l=md+1;
}
else {
r=md-1;
res=md;
// cout<<md<<" "<<coun[i]<<" "<<otv[i]<<"\n";
}
}
if(res==-1)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:47:21: warning: unused variable 'posl' [-Wunused-variable]
47 | ll l=1,r=q,res=-1,posl=0;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
10584 KB |
Output is correct |
2 |
Correct |
838 ms |
10708 KB |
Output is correct |
3 |
Correct |
270 ms |
10708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
354 ms |
10716 KB |
Output is correct |
2 |
Correct |
105 ms |
10588 KB |
Output is correct |
3 |
Correct |
1216 ms |
10712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6048 ms |
12952 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6055 ms |
12756 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6036 ms |
12892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6019 ms |
12888 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6007 ms |
14672 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
6022 ms |
14416 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |