#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define ff(i,s,f) for(ll i=s;i<f;i++)
#define fb(i,s,f) for(ll i=(s)-1;i>=f;i--)
#define ffi(i,s,f) for(ll i=s;i<=f;i++)
#define fbi(i,s,f) for(ll i=s;i>=f;i--)
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,ll) sort(a.begin(),a.end(),greater<ll>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define ub(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<ll,ll> pll;
typedef string str;
const ll maxn=5e5+10;
vector<ll> s[maxn];
ll p[maxn];
vector<ll> buckets[maxn];
ll res[maxn];
ll l[maxn];
ll r[maxn];
ll mid[maxn];
ll bit[maxn];
pair<pii,ll> ev[maxn];
void add(ll x,ll k,ll siz){
for(;x<=siz;x+=x&-x) bit[x]+=k;
}
ll query(ll x){
ll ret=0;
for(;x>0;x-=x&-x) ret+=bit[x];
return ret;
}
void solve(){
ll n,m; cin>>n>>m;
ff(i,0,m){
ll a; cin>>a;
s[a].pb(i+1);
}
ffi(i,1,n) cin>>p[i];
ll k; cin>>k;
ffi(i,1,k) cin>>ev[i].xx.xx>>ev[i].xx.yy>>ev[i].yy;
ffi(i,1,n) l[i]=1;
ffi(i,1,n) r[i]=k;
ffi(i,1,n) res[i]=-1;
bool change=true;
while(change){
change=false;
ffi(i,1,k) buckets[i].clear();
ffi(i,1,n) if(l[i]<=r[i]) change=true;
ffi(i,1,n) mid[i]=l[i]+(r[i]-l[i])/2;
ffi(i,1,n) if(l[i]<=r[i]) buckets[mid[i]].pb(i);
fill(bit,bit+m+1,0);
ffi(i,1,k){
if(ev[i].xx.xx<=ev[i].xx.yy){
add(ev[i].xx.xx,ev[i].yy,m);
add(ev[i].xx.yy+1,-ev[i].yy,m);
}else{
add(1,ev[i].yy,m);
add(ev[i].xx.yy+1,-ev[i].yy,m);
add(ev[i].xx.xx,ev[i].yy,m);
}
for(ll j:buckets[i]){
ll tren=0;
for(ll t:s[j]){
tren+=query(t);
if(tren>=p[j]) break;
}
if(tren>=p[j]){
res[j]=mid[j];
r[j]=mid[j]-1;
}else l[j]=mid[j]+1;
}
}
}
ffi(i,1,n)
if(res[i]!=-1) cout<<res[i]<<"\n";
else cout<<"NIE\n";
}
int main(){
ios;
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23884 KB |
Output is correct |
2 |
Correct |
17 ms |
23872 KB |
Output is correct |
3 |
Correct |
20 ms |
23884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
23888 KB |
Output is correct |
2 |
Correct |
16 ms |
23948 KB |
Output is correct |
3 |
Correct |
18 ms |
24016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
26976 KB |
Output is correct |
2 |
Correct |
134 ms |
30536 KB |
Output is correct |
3 |
Correct |
119 ms |
29208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
118 ms |
28480 KB |
Output is correct |
2 |
Correct |
115 ms |
28392 KB |
Output is correct |
3 |
Correct |
133 ms |
30904 KB |
Output is correct |
4 |
Correct |
48 ms |
27644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
27544 KB |
Output is correct |
2 |
Correct |
112 ms |
31040 KB |
Output is correct |
3 |
Correct |
62 ms |
25152 KB |
Output is correct |
4 |
Correct |
125 ms |
29928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
25908 KB |
Output is correct |
2 |
Correct |
120 ms |
28380 KB |
Output is correct |
3 |
Correct |
89 ms |
26512 KB |
Output is correct |
4 |
Correct |
165 ms |
32136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1292 ms |
58768 KB |
Output is correct |
2 |
Correct |
827 ms |
35708 KB |
Output is correct |
3 |
Correct |
265 ms |
29836 KB |
Output is correct |
4 |
Runtime error |
901 ms |
65540 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1231 ms |
56460 KB |
Output is correct |
2 |
Correct |
839 ms |
35656 KB |
Output is correct |
3 |
Correct |
217 ms |
28628 KB |
Output is correct |
4 |
Runtime error |
809 ms |
65540 KB |
Execution killed with signal 9 |