#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define gcd __gcd
#define sz(v) v.size()
#define pb push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
///#define int long long
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template<typename T> bool ckmx(T &a, T b){if(a < b) return a = b, true; return false;}
template<typename T> bool ckmn(T &a, T b){if(a > b) return a = b, true; return false;}
const int N = 3e5+5;
const ll MOD = 1e9+7;
const ll INF = 1e18;
int n, m, q, need[N], l[N], r[N];
int ql[N], qr[N], qad[N];
ll fen[N];
vector<int> state[N];
vector<int> md[N];
void update(int p, ll x){
for(; p <= m; p += p&-p){
fen[p] += x;
}
return;
}
void updateRange(int l, int r, ll val){
update(l, val);
update(r+1, -val);
return;
}
ll get(int x){
ll res = 0;
for(; x > 0; x -= x&-x){
res += fen[x];
}
return res;
}
void solve()
{
cin >> n >> m;
FOR(i, 1, m){
int x; cin >> x;
state[x].pb(i);
}
FOR(i, 1, n){
cin >> need[i];
}
cin >> q;
FOR(i, 1, q){
cin >> ql[i] >> qr[i] >> qad[i];
}
FOR(i, 1, n){
l[i] = 0, r[i] = q+1;
}
bool changed = true;
while(changed){
changed = false;
for(int i = 1; i <= m; i++) fen[i] = 0;
for(int i = 1; i <= n; i++){
if(l[i]+1 != r[i]){
md[(l[i]+r[i]>>1)].pb(i);
changed = true;
}
}
for(int i = 1; i <= q; i++){
///apply
if(ql[i] <= qr[i]) updateRange(ql[i], qr[i], qad[i]);
else updateRange(ql[i], m, qad[i]), updateRange(1, qr[i], qad[i]);
while(md[i].size()){
///check good
int cst = md[i].back(); md[i].pop_back();
ll sum = 0;
for(int sector : state[cst]){
sum += get(sector);
if(sum >= need[cst]) break;
}
if(sum >= need[cst]) r[cst] = i;
else l[cst] = i;
}
}
}
FOR(i, 1, n){
if(r[i] != q+1){
cout << r[i] <<"\n";
}
else cout << "NIE\n";
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#define name "InvMOD"
if(fopen(name".INP", "r")){
freopen(name".INP","r",stdin);
freopen(name".OUT","w",stdout);
}
int t = 1; //cin >> t;
while(t--) solve();
return 0;
}
Compilation message
met.cpp: In function 'void solve()':
met.cpp:81:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
81 | md[(l[i]+r[i]>>1)].pb(i);
| ~~~~^~~~~
met.cpp: In function 'int main()':
met.cpp:121:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
121 | freopen(name".INP","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
met.cpp:122:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
122 | freopen(name".OUT","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
23124 KB |
Output is correct |
2 |
Correct |
4 ms |
23124 KB |
Output is correct |
3 |
Correct |
4 ms |
23228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
23252 KB |
Output is correct |
2 |
Correct |
4 ms |
23124 KB |
Output is correct |
3 |
Correct |
5 ms |
23124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
45 ms |
24652 KB |
Output is correct |
2 |
Correct |
108 ms |
26940 KB |
Output is correct |
3 |
Correct |
80 ms |
26452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
26068 KB |
Output is correct |
2 |
Correct |
95 ms |
25932 KB |
Output is correct |
3 |
Correct |
107 ms |
26920 KB |
Output is correct |
4 |
Correct |
25 ms |
25184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
25164 KB |
Output is correct |
2 |
Correct |
83 ms |
27468 KB |
Output is correct |
3 |
Correct |
35 ms |
23892 KB |
Output is correct |
4 |
Correct |
84 ms |
26956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
24404 KB |
Output is correct |
2 |
Correct |
97 ms |
25916 KB |
Output is correct |
3 |
Correct |
55 ms |
24660 KB |
Output is correct |
4 |
Correct |
103 ms |
27996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1242 ms |
43272 KB |
Output is correct |
2 |
Correct |
820 ms |
32356 KB |
Output is correct |
3 |
Correct |
188 ms |
25676 KB |
Output is correct |
4 |
Correct |
1660 ms |
62248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1284 ms |
42068 KB |
Output is correct |
2 |
Correct |
812 ms |
30876 KB |
Output is correct |
3 |
Correct |
147 ms |
26444 KB |
Output is correct |
4 |
Correct |
1586 ms |
65536 KB |
Output is correct |