#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int,int,int> t3;
const int N=3e5+5;
struct fenwick{
ll tree[N]={};
void init(){
for(int i=0;i<N;++i)tree[i]=0;
}
void add(int i,ll v){
while(i<N){
tree[i]+=v;
i+=i&-i;
}
}
ll read(int i){
ll sum=0;
while(i>0){
sum+=tree[i];
i-=i&-i;
}
return sum;
}
}f;
int n,m,k;
int l[N],r[N],ans[N];
ll p[N];
vector<int> o[N];
vector<t3> v;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n >> m;
for(int i=1;i<=m;++i){
int x;
cin >> x;
o[x].push_back(i);
}
for(int i=1;i<=n;++i)cin >> p[i];
cin >> k;
v.emplace_back(0,0,0);
for(int i=1;i<=k;++i){
int a,b,c;
cin >> a >> b >> c;
v.emplace_back(a,b,c);
}
for(int i=1;i<=n;++i)l[i]=1,r[i]=k+1;
while(true){
vector<int> res[N];
int cnt=0;
for(int i=1;i<=n;++i){
if(l[i]>=r[i])continue;
res[(l[i]+r[i])/2].emplace_back(i);
++cnt;
}
if(cnt==0)break;
f.init();
for(int i=1;i<=k;++i){
auto [a,b,c]=v[i];
f.add(a,c);
f.add(b+1,-c);
if(b<a){
f.add(1,c);
f.add(m+1,-c);
}
for(auto j:res[i]){
ll sum=0;
for(auto x:o[j])sum+=f.read(x);
if(sum>=p[j])r[j]=i;
else l[j]=i+1;
if(l[j]>=r[j])ans[j]=r[j];
}
}
}
for(int i=1;i<=n;++i){
if(ans[i]<=k)cout << ans[i] << '\n';
else cout << "NIE" << '\n';
}
return 0;
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:65:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
65 | auto [a,b,c]=v[i];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
16844 KB |
Output is correct |
2 |
Correct |
20 ms |
16724 KB |
Output is correct |
3 |
Correct |
21 ms |
16816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
16824 KB |
Output is correct |
2 |
Correct |
20 ms |
16812 KB |
Output is correct |
3 |
Correct |
22 ms |
16828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
104 ms |
17864 KB |
Output is correct |
2 |
Correct |
155 ms |
18736 KB |
Output is correct |
3 |
Correct |
130 ms |
18380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
18184 KB |
Output is correct |
2 |
Correct |
146 ms |
18212 KB |
Output is correct |
3 |
Correct |
176 ms |
18888 KB |
Output is correct |
4 |
Correct |
50 ms |
17868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
17944 KB |
Output is correct |
2 |
Correct |
158 ms |
19036 KB |
Output is correct |
3 |
Correct |
140 ms |
17524 KB |
Output is correct |
4 |
Correct |
128 ms |
18672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
141 ms |
17816 KB |
Output is correct |
2 |
Correct |
186 ms |
18188 KB |
Output is correct |
3 |
Correct |
98 ms |
17836 KB |
Output is correct |
4 |
Correct |
159 ms |
19072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
922 ms |
27472 KB |
Output is correct |
2 |
Incorrect |
549 ms |
22056 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
849 ms |
26964 KB |
Output is correct |
2 |
Incorrect |
646 ms |
22088 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |