#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(v) v.begin(),v.end()
#define gcd(a,b) __gcd(a,b)
#define mt make_tuple
#define pqueue priority_queue
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
typedef tuple<int,int,int,int> iiii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<iii> viii;
typedef set<int> si;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<si> vsi;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
struct SegmentTree{
int n;
vector<ll> tree, lazy;
SegmentTree(int _n){
n = _n;
tree.assign(4*n + 5, 0);
lazy.assign(4*n + 5, 0);
}
void push(int node,int s,int e){
if (lazy[node] == 0) return;
tree[node] += lazy[node] * (e - s + 1);
if (s != e){
lazy[node*2] += lazy[node];
lazy[node*2+1] += lazy[node];
}
lazy[node] = 0;
}
void update(int node,int s,int e,int l,int r,int val){
push(node,s,e);
if (s > e || r < s || e < l) return;
if (l <= s && e <= r){
lazy[node] += val;
push(node,s,e);
return;
}
int m = (s+e)/2;
update(node*2,s,m,l,r,val);
update(node*2+1,m+1,e,l,r,val);
tree[node] = tree[node*2] + tree[node*2+1];
}
int query(int node,int s,int e,int x){
push(node,s,e);
if (s > e || x < s || e < x) return 0;
if (s == e && s == x) return tree[node];
int m = (s+e)/2;
return query(node*2,s,m,x) + query(node*2+1,m+1,e,x);
}
};
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("output.txt","w",stdout);
freopen("input.txt","r",stdin);
clock_t stime = clock();
#endif
int n,m,k;
cin >> n >> m;
vi sec(m,0),gerekli(n,0);
vvi devlet(n,vi());
for (int i = 0; i < m; i++){
cin >> sec[i];
sec[i]--;
devlet[sec[i]].pb(i);
}
for (int i = 0; i < n; i++) cin >> gerekli[i];
cin >> k;
viii queries(k+1);
for (int i = 1; i <= k; i++){
int l,r,x; cin >> l >> r >> x;
queries[i] = make_tuple(l-1,r-1,x);
}
vi left(n,1),right(n,k+1);
while (true){
SegmentTree tree(m);
vvi check(k+2);
bool ok = false;
for (int j = 0; j < n; j++){
if (left[j] <= right[j] - 1){
ok = true;
int mid = (left[j] + right[j]) / 2;
check[mid].pb(j);
}
}
if (!ok) break;
for (int j = 1; j <= k; j++){
int a,b,val; tie(a,b,val) = queries[j];
if (a <= b) tree.update(1,0,m-1,a,b,val);
if (a > b){
tree.update(1,0,m-1,a,m-1,val);
tree.update(1,0,m-1,0,b,val);
}
for (auto state : check[j]){
ll sum = 0;
for (auto s : devlet[state]){
sum += tree.query(1,0,m-1,s);
if (sum >= gerekli[state]) {
sum = gerekli[state];
break;
}
}
if (sum >= gerekli[state]) {
right[state] = j;
} else {
left[state] = j + 1;
}
}
}
}
for (int i = 0; i < n; i++){
if (left[i] == k+1) cout << "NIE" << endl;
else cout << left[i] << endl;
}
return 0;
}
Compilation message (stderr)
met.cpp: In function 'int32_t main()':
met.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
74 | freopen("output.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
75 | freopen("input.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |