This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |