#include <bits/stdc++.h>
using namespace std;
#define int 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; vi tree,lazy;
SegmentTree(int _n){
n = _n;
tree.assign(4*n + 100,0);
lazy.assign(4*n + 100,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);
}
};
int n,m,k;
vi sector;
vi meteors;
viii queries;
vvi devlet;
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
cin >> n >> m;
sector.assign(m+10,0);
meteors.assign(n+10,0);
devlet.assign(n+10,vi());
for (int i = 0; i < m; i++){
cin >> sector[i]; sector[i]--;
devlet[sector[i]].pb(i);
}
for (int i = 0; i < n; i++) cin >> meteors[i];
cin >> k;
queries.resize(k+10);
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+10,1),right(n+10,k+1);
for (int x = 0; x < ceil(log2(k+1)) + 10; x++){
SegmentTree tree(m);
vector<vi> check(k+10,vi());
for (int i = 0; i < n; i++) {
if (left[i] <= right[i] - 1){
int m = (left[i] + right[i]) / 2;
check[m].pb(i);
}
}
for (int i = 1; i <= k; i++){
int a,b,val; tie(a,b,val) = queries[i];
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 d : check[i]){
int sm = 0;
for (auto sector : devlet[d]){
sm += tree.query(1,0,m-1,sector);
}
if (sm >= meteors[d]){
right[d] = i;
}
else {
left[d] = i + 1;
}
}
}
}
for (int i = 0; i < n; i++){
if (left[i] == k+1) cout << "NIE" << endl;
else cout << left[i] << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
met.cpp: In function 'int32_t main()':
met.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
84 | freopen("output.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | 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... |