#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5 + 10;
struct FENWICK{
int fen[N];
int sz;
inline void init(int x){
sz = x+10;
memset(fen,0,sizeof(fen));
}
inline void update(int p , int x) {
while(p < sz){
fen[p] += x;
p += p & (-p);
//cout << "update:" << p << " " << sz << endl;
}
}
inline int query(int x){
int ret = 0;
while(x != 0){
ret += fen[x];
x -= x & (-x);
//cout <<"query:"<< x << endl;
}
return ret;
}
inline void rangeupdate(int l , int r,int x){
update(l,x);
update(r+1,-x);
}
};
void solve(){
int n,m;cin >> n >> m;
vector < int > devlet[n+1];
for(int i = 1;i<=m;i++){
int x;cin >> x;
devlet[x].push_back(i);
}
int need[n+5];
for(int i = 1;i<=n;i++){
cin >> need[i];
}
int q;cin >> q;
vector < array < int , 3 > > query(q+5);
for(int i = 1;i<=q;i++){
cin >> query[i][0] >> query[i][1] >> query[i][2];
}
vector < array < int , 3 > > paralel[q+5],nparalel[q+5];
for(int i = 1;i<=n;i++){
paralel[(1+q+1)/2].push_back({i,1,q+1});
}
FENWICK fen;
for(int i = 0;i<=25;i++){
fen.init(m+10);
for(int j = 1;j<=q;j++){
if(query[j][0] <= query[j][1]){
fen.rangeupdate(query[j][0],query[j][1],query[j][2]);
}
else{
fen.rangeupdate(1,query[j][1],query[j][2]);
fen.rangeupdate(query[j][0],m,query[j][2]);
}
for(auto itr : paralel[j]){
if(itr[1] == itr[2]){
nparalel[j].push_back(itr);
continue;
}
int cur = 0;
for(auto itr1 : devlet[itr[0]]){
cur += fen.query(itr1);
}
if(cur >= need[itr[0]]){//r = mid;
int mid = (itr[1] + j)/2;
nparalel[mid].push_back({itr[0],itr[1],j});
}
else {//l = mid
int mid = (j+1 + itr[2])/2;
nparalel[mid].push_back({itr[0],j+1,itr[2]});
}
}
}
for(int j = 1;j<=q+1;j++){
paralel[j].swap(nparalel[j]);
nparalel[j].clear();
}
}
int ans[n+5];
memset(ans , -1 , sizeof(ans));
for(int j = 1;j<=q;j++){
for(auto itr : paralel[j]){
ans[itr[0]] = j;
}
}
for(int i = 1;i<=n;i++){
if(ans[i] == -1)cout << "NIE" << '\n';
else cout << ans[i] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2908 KB |
Output is correct |
2 |
Correct |
4 ms |
2908 KB |
Output is correct |
3 |
Correct |
4 ms |
2844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
2908 KB |
Output is correct |
2 |
Correct |
4 ms |
3020 KB |
Output is correct |
3 |
Correct |
4 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
9120 KB |
Output is correct |
2 |
Correct |
119 ms |
17976 KB |
Output is correct |
3 |
Correct |
106 ms |
14156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
12116 KB |
Output is correct |
2 |
Correct |
111 ms |
12092 KB |
Output is correct |
3 |
Correct |
124 ms |
19240 KB |
Output is correct |
4 |
Correct |
29 ms |
10076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
93 ms |
9724 KB |
Output is correct |
2 |
Correct |
94 ms |
18936 KB |
Output is correct |
3 |
Correct |
58 ms |
6492 KB |
Output is correct |
4 |
Correct |
106 ms |
15876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
6872 KB |
Output is correct |
2 |
Correct |
112 ms |
12176 KB |
Output is correct |
3 |
Correct |
79 ms |
8000 KB |
Output is correct |
4 |
Correct |
132 ms |
21192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
651 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
704 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |