# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
680320 |
2023-01-10T14:51:23 Z |
browntoad |
Meteors (POI11_met) |
C++14 |
|
1311 ms |
31632 KB |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
using namespace std;
#define ll long long
// #define int ll
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n+1)
#define RREP(i, n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)((x).size())
#define SQ(x) (x)*(x)
#define f first
#define s second
#define pii pair<int, int>
#define endl '\n'
#define pb push_back
const ll mod = 1e9+7;
const ll maxn = 3e5+5;
const ll inf = (1ll<<60);
const ll iinf = 2e9;
ll pw(ll x, ll p){
ll ret=1;
while(p>0){
if (p&1){
ret*=x;
ret%=mod;
}
x*=x;
x%=mod;
p>>=1;
}
return ret;
}
ll inv(ll x){
return pw(x, mod-2);
}
int n, m, k;
vector<int> need(maxn), ans(maxn);
vector<int> ids[maxn];
long long bit[maxn], incbit[maxn];
void modify(int a, int val){
while(a<=m){
bit[a]+=val;
a+=(a&-a);
}
}
void modify2(int a, int val){
while(a<=m){
incbit[a]+=val;
a+=(a&-a);
}
}
long long ret=0;
long long query(int a){
ret=0;
while(a>0){
ret+=bit[a];
a-=(a&-a);
}
return ret;
}
long long query2(int a){
ret=0;
while(a>0){
ret+=incbit[a];
a-=(a&-a);
}
return ret;
}
struct mods{
int l, r;
int w;
};
vector<mods> quer;
long long tmpv=0;
void run(int L, int R, vector<int> &vals){
if (L>R) return;
if (L==R){
REP(i, SZ(vals)){
if (L==k) ans[vals[i]]=-1;
else ans[vals[i]]=L+1;
}
if (L!=k){
if (quer[L].l<=quer[L].r){
modify2(quer[L].l, quer[L].w);
modify2(quer[L].r+1, -quer[L].w);
}
else {
modify2(quer[L].l, quer[L].w);
modify2(m+1, -quer[L].w);
modify2(1, quer[L].w);
modify2(quer[L].r+1, -quer[L].w);
}
}
return;
}
int mid = (L+R)>>1;
FOR(i, L, mid+1){
if (quer[i].l<=quer[i].r){
modify(quer[i].l, quer[i].w);
modify(quer[i].r+1, -quer[i].w);
}
else {
modify(quer[i].l, quer[i].w);
modify(m+1, -quer[i].w);
modify(1, quer[i].w);
modify(quer[i].r+1, -quer[i].w);
}
}
vector<int> aL, aR;
REP(i, SZ(vals)){
tmpv=0;
REP(j, SZ(ids[vals[i]])){
tmpv+=query(ids[vals[i]][j])+query2(ids[vals[i]][j]);
if (tmpv>=(ll)(need[vals[i]])) break;
}
if (tmpv>=(ll)(need[vals[i]])){
aL.pb(vals[i]);
}
else{
aR.pb(vals[i]);
}
}
// undo
FOR(i, L, mid+1){
if (quer[i].l<=quer[i].r){
modify(quer[i].l, -quer[i].w);
modify(quer[i].r+1, quer[i].w);
}
else {
modify(quer[i].l, -quer[i].w);
modify(m+1, quer[i].w);
modify(1, -quer[i].w);
modify(quer[i].r+1, quer[i].w);
}
}
run(L, mid, aL);
run(mid+1, R, aR);
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin>>n>>m;
vector<int> tmp(n);
REP(i, n){
tmp[i]=i+1;
}
int a;
REP1(i, m){
cin>>a;
ids[a].pb(i);
}
REP1(i, n){
cin>>need[i];
}
cin>>k;
int x, y, z;
REP(i, k){
cin>>x>>y>>z;
quer.pb({x, y, z});
}
fill(ALL(ans), -1);
run(0, k, tmp);
REP1(i, n){
if (ans[i]==-1) cout<<"NIE"<<endl;
else cout<<ans[i]<<endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
6 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9748 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
11804 KB |
Output is correct |
2 |
Correct |
105 ms |
13512 KB |
Output is correct |
3 |
Correct |
82 ms |
11832 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
11688 KB |
Output is correct |
2 |
Correct |
87 ms |
11704 KB |
Output is correct |
3 |
Correct |
94 ms |
12856 KB |
Output is correct |
4 |
Correct |
29 ms |
11628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
11648 KB |
Output is correct |
2 |
Correct |
79 ms |
13084 KB |
Output is correct |
3 |
Correct |
41 ms |
10596 KB |
Output is correct |
4 |
Correct |
88 ms |
12040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
11544 KB |
Output is correct |
2 |
Correct |
86 ms |
11704 KB |
Output is correct |
3 |
Correct |
66 ms |
11544 KB |
Output is correct |
4 |
Correct |
104 ms |
12600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
962 ms |
27160 KB |
Output is correct |
2 |
Correct |
564 ms |
19596 KB |
Output is correct |
3 |
Correct |
209 ms |
12876 KB |
Output is correct |
4 |
Correct |
1179 ms |
28604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
931 ms |
25980 KB |
Output is correct |
2 |
Correct |
607 ms |
19448 KB |
Output is correct |
3 |
Correct |
162 ms |
12912 KB |
Output is correct |
4 |
Correct |
1311 ms |
31632 KB |
Output is correct |