# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
548536 |
2022-04-13T18:14:01 Z |
2fat2code |
Meteors (POI11_met) |
C++17 |
|
3839 ms |
63456 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 800005;
int n, m, k, a[nmax], p[nmax], x[nmax], y[nmax], z[nmax], ans[nmax], curr, tree[4*nmax], lazy[4*nmax];
vector<int>members[nmax];
void push(int l, int r, int nod){
tree[nod] += lazy[nod];
if(l != r){
lazy[2*nod] += lazy[nod];
lazy[2*nod + 1] += lazy[nod];
}
lazy[nod] = 0;
}
void add(int l, int r, int le, int ri, int val, int nod){
push(l, r, nod);
if(r < le || l > ri) return;
else if(l >= le && r <= ri){
lazy[nod] += val;
push(l, r, nod);
}
else{
int mid = l + (r - l) / 2;
add(l, mid, le, ri, val, 2*nod);
add(mid + 1, r, le, ri, val, 2*nod + 1);
tree[nod] = tree[2*nod] + tree[2*nod + 1];
}
}
int query(int l, int r, int le, int ri, int nod){
push(l, r, nod);
if(r < le || l > ri) return 0;
else if(l >= le && r <= ri){
return tree[nod];
}
else{
int mid = l + (r - l) / 2;
return query(l, mid, le, ri, 2*nod) + query(mid + 1, r, le, ri, 2*nod + 1);
}
}
void rec(int l, int r, vector<int>&pending){
if(r < l) return;
int mid = l + (r - l) / 2;
while(curr < mid){
curr++;
if(x[curr] <= y[curr]) add(1, m, x[curr], y[curr], z[curr], 1);
else{
add(1, m, x[curr], m, z[curr], 1);
add(1, m, 1, y[curr], z[curr], 1);
}
}
while(curr > mid){
if(x[curr] <= y[curr]) add(1, m, x[curr], y[curr], -z[curr], 1);
else{
add(1, m, x[curr], m, -z[curr], 1);
add(1, m, 1, y[curr], -z[curr], 1);
}
--curr;
}
vector<int>good;
vector<int>bad;
for(auto it : pending){
int curr = 0;
for(auto it1 : members[it]){
curr += query(1, m, it1, it1, 1);
}
if(curr >= p[it]){
good.push_back(it);
ans[it] = mid;
}
else{
bad.push_back(it);
}
}
pending.clear();
if(l != r){
rec(l, mid - 1, good);
rec(mid + 1, r, bad);
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
//freopen("input.in", "r", stdin);
cin >> n >> m;
for(int i=1;i<=m;i++){
cin >> a[i];
members[a[i]].push_back(i);
}
for(int i=1;i<=n;i++){ cin >> p[i];}
cin >> k;
for(int i=1;i<=k;i++){
cin >> x[i] >> y[i] >> z[i];
}
vector<int>tz;
for(int i=1;i<=n;i++) tz.push_back(i);
rec(1, k, tz);
for(int i=1;i<=n;i++){
if(!ans[i]){
cout << "NIE" << '\n';
}
else{
cout << ans[i] << '\n';
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
19284 KB |
Output is correct |
2 |
Correct |
13 ms |
19284 KB |
Output is correct |
3 |
Correct |
12 ms |
19156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
19204 KB |
Output is correct |
2 |
Correct |
14 ms |
19412 KB |
Output is correct |
3 |
Correct |
18 ms |
19356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
313 ms |
25008 KB |
Output is correct |
2 |
Correct |
413 ms |
28368 KB |
Output is correct |
3 |
Correct |
376 ms |
25272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
24916 KB |
Output is correct |
2 |
Correct |
350 ms |
24908 KB |
Output is correct |
3 |
Correct |
392 ms |
27004 KB |
Output is correct |
4 |
Correct |
134 ms |
24256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
252 ms |
24632 KB |
Output is correct |
2 |
Correct |
330 ms |
27392 KB |
Output is correct |
3 |
Correct |
119 ms |
20960 KB |
Output is correct |
4 |
Correct |
350 ms |
25324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
337 ms |
24232 KB |
Output is correct |
2 |
Correct |
351 ms |
24824 KB |
Output is correct |
3 |
Correct |
310 ms |
24320 KB |
Output is correct |
4 |
Correct |
364 ms |
26672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3839 ms |
63456 KB |
Output is correct |
2 |
Incorrect |
2286 ms |
48488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3678 ms |
60104 KB |
Output is correct |
2 |
Incorrect |
1662 ms |
48364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |