#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
int const maxn = 3e5+7;
const ll INF = LLONG_MAX;
int n , m , q;
int x[maxn] ;
int l[maxn] , r[maxn];
int le[maxn] , ri[maxn];
ll v[maxn] , a[maxn];
vector<int> adj[maxn];
vector<int> stage , temp;
struct Fw
{
ll bit[maxn];
Fw()
{
memset(bit , 0 , sizeof(bit));
}
void Clear()
{
memset(bit , 0 , sizeof(bit));
}
void Upd(int u , ll v)
{
int idx = u;
while(idx <= m){
bit[idx] += v;
idx += (idx & (- idx));
}
}
ll Get(int u)
{
ll re = 0;
int idx = u;
while(idx){
re += bit[idx];
idx -= (idx & (- idx));
}
return re;
}
};
Fw Fen;
void Update(int pos)
{
Fen.Upd(l[pos] , v[pos]);
Fen.Upd(r[pos] + 1 , - v[pos]);
if(l[pos] > r[pos]){
Fen.Upd(1 , v[pos]);
}
}
ll Get_sum(int pos)
{
ll re = 0;
for(auto u : adj[pos]){
re += Fen.Get(u);
}
return re;
}
void Input()
{
cin >> n >> m;
for(int i = 1 ; i <= m ; i ++){
cin >> x[i];
adj[x[i]].pb(i);
}
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
}
cin >> q;
for(int i = 1 ; i <= q ; i ++){
cin >> l[i] >> r[i] >> v[i];
}
}
bool cmp(int x , int y)
{
return (le[x] + ri[x]) / 2 < (le[y] + ri[y]) / 2;
}
void Solve()
{
for(int i = 1 ; i <= n ; i ++){
stage.pb(i);
le[i] = 1;
ri[i] = q;
}
while(stage.size() != 0){
sort(stage.begin() , stage.end() , cmp);
int run = 1;
for(auto u : stage){
int mid = (le[u] + ri[u]) / 2;
while(run <= mid){
Update(run);
run ++;
}
ll s = Get_sum(u);
if(s < a[u]) le[u] = mid + 1;
else ri[u] = mid - 1;
if(le[u] <= ri[u]) temp.pb(u);
}
// cout << "Check " << "\n";
// for(int i = 1 ; i <= n ; i ++){
// cout << le[i] << " " << ri[i] << "\n";
// }
swap(stage , temp);
temp.clear();
Fen.Clear();
}
for(int i = 1 ; i <= n ; i ++){
// cout << "le " << le[i] << "\n";
le[i] > q ? cout << "NIE" : cout << le[i];
cout << "\n";
}
}
int main()
{
// freopen(".INP","r",stdin);
// freopen(".OUT","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
Input();
Solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
19036 KB |
Output is correct |
2 |
Correct |
3 ms |
19036 KB |
Output is correct |
3 |
Correct |
3 ms |
19128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
19036 KB |
Output is correct |
2 |
Correct |
3 ms |
19036 KB |
Output is correct |
3 |
Correct |
3 ms |
19036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
19544 KB |
Output is correct |
2 |
Correct |
84 ms |
20264 KB |
Output is correct |
3 |
Correct |
59 ms |
20048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
19804 KB |
Output is correct |
2 |
Correct |
60 ms |
19884 KB |
Output is correct |
3 |
Correct |
83 ms |
20316 KB |
Output is correct |
4 |
Correct |
22 ms |
20060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
19804 KB |
Output is correct |
2 |
Correct |
66 ms |
20312 KB |
Output is correct |
3 |
Correct |
16 ms |
19036 KB |
Output is correct |
4 |
Correct |
58 ms |
20160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
19548 KB |
Output is correct |
2 |
Correct |
72 ms |
19876 KB |
Output is correct |
3 |
Correct |
40 ms |
19548 KB |
Output is correct |
4 |
Correct |
80 ms |
20560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
881 ms |
25472 KB |
Output is correct |
2 |
Correct |
101 ms |
21572 KB |
Output is correct |
3 |
Correct |
86 ms |
21336 KB |
Output is correct |
4 |
Correct |
1074 ms |
37656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
865 ms |
25220 KB |
Output is correct |
2 |
Correct |
446 ms |
21476 KB |
Output is correct |
3 |
Correct |
33 ms |
22352 KB |
Output is correct |
4 |
Correct |
1216 ms |
39232 KB |
Output is correct |