#include <bits/stdc++.h>
#define endl "\n"
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz size()
#define rep(i,k,n) for(int i = k ; i <= n ; ++i)
#define per(i,k,n) for(int i = k ; i >= n ; --i)
#define YOSIK() ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define fr(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define toqta return 0
#define PERMUTE next_permutation
#define no cout<<"No"<<endl;
#define yes cout<<"Yes"<<endl;
#define a() a + 1, a + n + 1
#define int long long
using namespace std;
/*
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse,-fgcse-lm")
#pragma GCC optimize("-ftree-pre,-ftree-vrp")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
*/
typedef long long ll;
typedef unsigned long long ull;
typedef string S;
typedef double D;
typedef long double lld;
const int N = 3e5 + 17;
const int modd = 1e9 + 7;
const ll INF = 1e18 - 19;
const int P = 37;
const ll NN = 1e7 + 17;
const D eps = 1e-19;
const double pi = 3.141592653589793238462643383279 ;
struct edge {
ll a, b, len;
bool operator<(const edge& other) {
return len < other.len;
}
};
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b){
return (a.second < b.second);
}
void pre (ll a) {
cout << fixed << setprecision(a);
return;
}
ll n, m, q;
ll L[N], R[N], x[N];
ll sum[N], a[N], t[N * 4];
vector <ll> p[N];
void push (ll v, ll l, ll r) {
if (t[v] != 0 && l != r) {
t[v * 2] += t[v];
t[v * 2 + 1] += t[v];
t[v] = 0;
}
}
void update (ll v, ll tl, ll tr, ll l, ll r, ll val) {
if (l <= tl && tr <= r) {
t[v] += val;
push(v, tl, tr);
return;
}
if (tr < l || r < tl) return;
push (v, tl, tr);
ll mid = tl + tr >> 1;
update (v * 2, tl, mid, l, r, val);
update (v * 2 + 1, mid + 1, tr, l, r, val);
}
ll get (ll v, ll l, ll r, ll pos) {
if (l == r) return t[v];
ll mid = l + r >> 1;
push (v, l, r);
if (pos <= mid) return get (v * 2, l, mid, pos);
else return get (v * 2 + 1, mid + 1, r, pos);
}
ll check (ll pos, ll id) {
ll ans = 0;
for (int i = 1; i <= pos; ++ i) {
if (L[i] > R[i]) {
update (1, 1, m, L[i], m, x[i]);
update (1, 1, m, 1, R[i], x[i]);
} else {
update (1, 1, m, L[i], R[i], x[i]);
}
}
for (auto i: p[id]) ans += get (1, 1, m, i);
for (int i = 1; i <= m * 4; ++ i) t[i] = 0;
return ans;
}
vector <ll> MID[N];
pair <ll, ll> pr[N];
void Solution (/*Nuraly.Serikbay*/) {
cin >> n >> m;
for (int i = 1; i <= m; ++ i) {
cin >> a[i];
p[a[i]].pb (i);
}
for (int i = 1; i <= n; ++ i) cin >> sum[i];
cin >> q;
for (int i = 1; i <= q; ++ i) cin >> L[i] >> R[i] >> x[i];
for (int i = 1; i <= n; ++ i) pr[i] = {0, q + 1};
for (int tt = 1; tt <= 23; ++ tt) {
for (int i = 1; i <= n; ++ i) MID[pr[i].F + pr[i].S >> 1].pb (i);
for (int mid = 1; mid <= q; ++ mid) {
if (L[mid] > R[mid]) {
update (1, 1, m, L[mid], m, x[mid]);
update (1, 1, m, 1, R[mid], x[mid]);
} else {
update (1, 1, m, L[mid], R[mid], x[mid]);
}
for (auto to: MID[mid]) {
ll ans = 0;
for (auto u: p[to]) ans += get (1, 1, m, u);
if (ans >= sum[to]) pr[to].S = mid;
else pr[to].F = mid;
}
}
for (int i = 1; i <= m * 4; ++ i) t[i] = 0;
for (int i = 0; i <= q + 1; ++ i) MID[i].clear ();
}
for (int i = 1; i <= n; ++ i) {
if (pr[i].S == q + 1) cout << "NIE\n";
else cout << pr[i].S << '\n';
}
return;
}
main () {
YOSIK();
ll T = 1;
//cin >> T;
while (T --) {
Solution ();
}
exit (0);
}/*
*/
Compilation message
met.cpp: In function 'void update(ll, ll, ll, ll, ll, ll)':
met.cpp:89:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
89 | ll mid = tl + tr >> 1;
| ~~~^~~~
met.cpp: In function 'll get(ll, ll, ll, ll)':
met.cpp:96:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
96 | ll mid = l + r >> 1;
| ~~^~~
met.cpp: In function 'void Solution()':
met.cpp:132:45: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
132 | for (int i = 1; i <= n; ++ i) MID[pr[i].F + pr[i].S >> 1].pb (i);
| ^
met.cpp: At global scope:
met.cpp:157:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
157 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
14540 KB |
Output is correct |
2 |
Correct |
14 ms |
14556 KB |
Output is correct |
3 |
Correct |
13 ms |
14568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
14592 KB |
Output is correct |
2 |
Correct |
14 ms |
14584 KB |
Output is correct |
3 |
Correct |
17 ms |
14604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
457 ms |
19000 KB |
Output is correct |
2 |
Correct |
562 ms |
22516 KB |
Output is correct |
3 |
Correct |
547 ms |
21244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
500 ms |
20436 KB |
Output is correct |
2 |
Correct |
528 ms |
20676 KB |
Output is correct |
3 |
Correct |
565 ms |
22680 KB |
Output is correct |
4 |
Correct |
122 ms |
19692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
19420 KB |
Output is correct |
2 |
Correct |
360 ms |
22872 KB |
Output is correct |
3 |
Correct |
246 ms |
15756 KB |
Output is correct |
4 |
Correct |
515 ms |
21836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
491 ms |
18196 KB |
Output is correct |
2 |
Correct |
463 ms |
20460 KB |
Output is correct |
3 |
Correct |
460 ms |
18636 KB |
Output is correct |
4 |
Correct |
570 ms |
24112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4395 ms |
57240 KB |
Output is correct |
2 |
Incorrect |
2127 ms |
35696 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4344 ms |
55024 KB |
Output is correct |
2 |
Incorrect |
1322 ms |
35564 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |