This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define optimus_prime ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fxd(x) fixed << setprecision(x)
#define all(a) (a.begin() , a.end())
#define popcount(x) __builtin_popcount(x)
#define lwb lower_bound
#define upb upper_bound
#define dl double long
#define ll long long
#define pb push_back
#define sz() size()
#define F first
#define S second
using namespace std;
const ll N = 3e5+9;
const ll inf=1e9+9;
const ll mod=1e9+7;
const ll P = 37;
map <int , int> mp;
ll n , m , q , p , a[N] , ans[N] , sum[N] , timer , t[N*4];
vector <int> g[N];
void build(ll v=1 , ll tl=1 , ll tr=m){
if (tl==tr){
t[v]=1;
return;
}
ll tm=(tl+tr)>>1;
build(v*2 , tl , tm);
build(v*2|1 , tm+1 , tr);
t[v]=t[v*2]+t[v*2|1];
}
ll get(ll l , ll r , ll v=1 , ll tl=1 , ll tr=m){
if (l<=tl&&tr<=r)return t[v];
if (r<tl||tr<l)return 0;
ll tm=(tl+tr)>>1;
return get(l , r , v*2 , tl , tm)+get(l , r , v*2|1 , tm+1 , tr);
}
void upd(ll pos , ll v=1 , ll tl=1 , ll tr=m){
if (tl==tr){
t[v]=0;
return;
}
ll tm=(tl+tr)>>1;
if (pos<=tm)upd(pos , v*2 , tl , tm);
else upd(pos , v*2|1 , tm+1 , tr);
}
void solve(){
cin >> n >> m;
for (int i = 1 ; i <= m ; i++){
cin >> p;
mp[i]=p;
g[p].pb(i);
}
for (int i = 1 ; i <= n ; i++)cin >> a[i];
build();
cin >> q;
while (q--){
timer++;
ll l , r , x;
cin >> l >> r >> x;
if (l<=r){
if (get(l , r)){
for (int i = l ; i <= r ; i++){
sum[mp[i]]+=x;
if (sum[mp[i]]>=a[mp[i]]&&!ans[mp[i]]){
ans[mp[i]]=timer;
for (auto to : g[mp[i]])upd(to);
}
}
}
}
else {
if (get(l , m)){
for (int i = l ; i <= m ; i++){
sum[mp[i]]+=x;
if (sum[mp[i]]>=a[mp[i]]&&!ans[mp[i]]){
ans[mp[i]]=timer;
for (auto to : g[mp[i]])upd(to);
}
}
}
if (get(1 , r)){
for (int i = 1 ; i <= r ; i++){
sum[mp[i]]+=x;
if (sum[mp[i]]>=a[mp[i]]&&!ans[mp[i]]){
ans[mp[i]]=timer;
for (auto to : g[mp[i]])upd(to);
}
}
}
}
}
for (int i = 1; i<= n ; i++){
if (!ans[i])cout << "NIE\n";
else cout << ans[i] << "\n";
}
}
signed main() {
optimus_prime;
ll t=1;
while (t--)solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |