#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef long double ld;
//#define int long long
#define all(x) x.begin(),x.end()
#define pb push_back
#define ent "\n"
const int maxn = (int)3e5 + 1;
const int amirr = (int)1e9;
int n,m;
vector<int>pos[maxn],MID[maxn];
int a[maxn];
int l[maxn],r[maxn],w[maxn];
pair<int,int>seg[maxn];
ll t[maxn * 4];
void push (int v, int tl, int tr) {
if (t[v] && tl != tr) {
t[v + v] += t[v], t[v + v + 1] += t[v];
t[v] = 0;
}
return;
}
void upd (int v, int tl, int tr, int l, int r, int val) {
push (v, tl, tr);
if (tr < l || r < tl) return;
if (l <= tl && tr <= r) {
t[v] += val;
push (v, tl, tr);
return;
}
int mid = (tl + tr) >> 1;
upd (v + v, tl, mid, l, r, val);
upd (v + v + 1, mid + 1, tr, l, r, val);
return;
}
int get (int v, int tl, int tr, int pos) {
push (v, tl, tr);
if (tl == tr || t[v] >= amirr) return t[v];
int mid = (tl + tr) >> 1;
if (pos <= mid) return get (v + v, tl, mid, pos);
return get (v + v + 1, mid + 1, tr, pos);
}
int ans[maxn];
void solve(){
cin >> n >> m;
for(int i = 1 ; i <= m ; i ++){
int o;cin >> o;
pos[o].pb(i);
}
for(int i = 1 ; i <= n ; i ++){
cin >> a[i];
}
int k;cin >> k;
for(int i = 1 ; i <= k ; i++){
cin >> l[i] >> r[i] >> w[i];
}
for(int i = 1 ; i <= n ; i ++){
seg[i] = {1, k};
}
bool ok = 1;
while(ok){
memset (t, 0, sizeof(t));
ok = 0;
for(int i = 1 ; i <= n ; i ++){
if(seg[i].first <= seg[i].second){
int mid = (seg[i].first + seg[i].second) >> 1;
MID[mid].pb(i);
ok = 1;
}
}
for(int i = 1 ; i <= k ; i ++){
if(l[i] <= r[i]){
upd(1,1,m,l[i],r[i],w[i]);
}
else{
upd(1,1,m,l[i],m,w[i]);
upd(1,1,m,1,r[i],w[i]);
}
ll sum = 0;
for(int x : MID[i]){
sum = 0;
for(int y : pos[x]){
sum += get (1, 1, m, y);
if(sum >= a[x])break;
}
if(sum >= a[x]){
seg[x].second = i - 1;
ans[x] = i;
}
else{
seg[x].first = i + 1;
}
}
MID[i].clear();
}
}
for(int i = 1 ; i <= n ; i ++){
if (ans[i] == 0) cout << "NIE\n";
else cout << ans[i] << '\n';
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
//cin >> t;
while(t --){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
31832 KB |
Output is correct |
2 |
Correct |
11 ms |
31916 KB |
Output is correct |
3 |
Correct |
12 ms |
31836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
31832 KB |
Output is correct |
2 |
Correct |
11 ms |
32016 KB |
Output is correct |
3 |
Correct |
12 ms |
31832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
322 ms |
32596 KB |
Output is correct |
2 |
Correct |
406 ms |
34720 KB |
Output is correct |
3 |
Correct |
401 ms |
34244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
370 ms |
33720 KB |
Output is correct |
2 |
Correct |
374 ms |
33568 KB |
Output is correct |
3 |
Correct |
380 ms |
34636 KB |
Output is correct |
4 |
Correct |
70 ms |
33616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
33108 KB |
Output is correct |
2 |
Correct |
196 ms |
35156 KB |
Output is correct |
3 |
Correct |
181 ms |
32084 KB |
Output is correct |
4 |
Correct |
386 ms |
34620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
348 ms |
32296 KB |
Output is correct |
2 |
Correct |
298 ms |
33620 KB |
Output is correct |
3 |
Correct |
350 ms |
32564 KB |
Output is correct |
4 |
Correct |
392 ms |
35748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3275 ms |
44332 KB |
Output is correct |
2 |
Incorrect |
1125 ms |
33544 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3257 ms |
43420 KB |
Output is correct |
2 |
Incorrect |
807 ms |
33288 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |