# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
655138 |
2022-11-03T08:35:27 Z |
snpmrnhlol |
Meteors (POI11_met) |
C++17 |
|
2084 ms |
43396 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll v[300000],v2[300000],l[300000],r[300000];
ll v3[300000],v4[300000],v5[300000];
vector <ll> v7[300000];
struct event{
int t,id;
}v6[300000];
bool cmp(event a,event b){
return a.t < b.t;
}
class fenwick{
ll fen[300001];
public:
ll query(ll pos){
pos++;
ll r = 0;
for(ll i = pos;i > 0;i-=(i&-i))r+=fen[i];
//cout<<"query:"<<pos - 1<<",result:"<<r<<'\n';
return r;
}
void add(ll pos,ll nr){
//cout<<"added:"<<pos<<','<<nr<<'\n';
pos++;
for(ll i = pos;i <= 300000;i+=(i&-i))fen[i]+=nr;
}
void empt(){
for(ll i = 0;i <= 300000;i++)fen[i] = 0;
//cout<<"emptied\n";
}
};
fenwick fen;
bool calc(ll nr,ll nr2){
ll r = 0;
for(auto i:v7[nr]){
//cout<<i<<' '<<fen.query(i)<<'\n';
r+=fen.query(i);
if(r >= nr2)return 1;
}
return 0;
}
int main(){
ll n,m,i,q,j,cnt = 0;
cin>>n>>m;
for(i = 0;i < m;i++)cin>>v[i],v[i]--,v7[v[i]].push_back(i);;
for(i = 0;i < n;i++){
cin>>v2[i];
}
cin>>q;
for(i = 0;i < q;i++){
cin>>v3[i]>>v4[i]>>v5[i];
v3[i]--;
v4[i]--;
}
for(i = 0;i < n;i++)l[i] = 0,r[i] = q;
for(i = 0;i < 20;i++){
fen.empt();
cnt = 0;
for(j = 0;j < n;j++){
if(l[j] != r[j]){
v6[cnt++] = {(l[j] + r[j])/2,j};
}
}
sort(v6,v6 + cnt,cmp);
ll p1 = 0;
///simulate
for(j = 0;j < q;j++){
//cout<<"adding query:"<<j<<',';
if(v3[j] <= v4[j]){
fen.add(v3[j],v5[j]);
fen.add(v4[j] + 1,-v5[j]);
}else{
swap(v3[j],v4[j]);
fen.add(0,v5[j]);
fen.add(v3[j] + 1,-v5[j]);
fen.add(v4[j],v5[j]);
swap(v3[j],v4[j]);
}
while(p1 < cnt && v6[p1].t == j){
if(calc(v6[p1].id,v2[v6[p1].id])){
r[v6[p1].id] = j;
}else{
l[v6[p1].id] = j + 1;
}
p1++;
}
}
}
for(i = 0;i < n;i++){
if(l[i] == q)cout<<"NIE";
else cout<<l[i] + 1;
cout<<'\n';
}
return 0;
}
/**
3 5
1 3 2 1 3
8 1 8
3
4 2 4
1 3 1
3 5 2
**/
Compilation message
met.cpp: In function 'int main()':
met.cpp:62:43: warning: narrowing conversion of '((l[j] + r[j]) / 2)' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
62 | v6[cnt++] = {(l[j] + r[j])/2,j};
| ~~~~~~~~~~~~~^~
met.cpp:62:46: warning: narrowing conversion of 'j' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
62 | v6[cnt++] = {(l[j] + r[j])/2,j};
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9812 KB |
Output is correct |
2 |
Correct |
9 ms |
9812 KB |
Output is correct |
3 |
Correct |
9 ms |
9812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9812 KB |
Output is correct |
2 |
Correct |
9 ms |
9812 KB |
Output is correct |
3 |
Correct |
11 ms |
9756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
12060 KB |
Output is correct |
2 |
Correct |
212 ms |
12936 KB |
Output is correct |
3 |
Correct |
143 ms |
12508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
162 ms |
12236 KB |
Output is correct |
2 |
Correct |
167 ms |
12312 KB |
Output is correct |
3 |
Correct |
204 ms |
13000 KB |
Output is correct |
4 |
Correct |
49 ms |
11500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
12100 KB |
Output is correct |
2 |
Correct |
256 ms |
12868 KB |
Output is correct |
3 |
Correct |
158 ms |
10948 KB |
Output is correct |
4 |
Correct |
147 ms |
12616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
167 ms |
11844 KB |
Output is correct |
2 |
Correct |
185 ms |
12264 KB |
Output is correct |
3 |
Correct |
119 ms |
11964 KB |
Output is correct |
4 |
Correct |
192 ms |
13116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1306 ms |
28072 KB |
Output is correct |
2 |
Correct |
882 ms |
21596 KB |
Output is correct |
3 |
Correct |
708 ms |
15640 KB |
Output is correct |
4 |
Correct |
1859 ms |
41312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1243 ms |
27376 KB |
Output is correct |
2 |
Correct |
922 ms |
21600 KB |
Output is correct |
3 |
Correct |
576 ms |
14460 KB |
Output is correct |
4 |
Correct |
2084 ms |
43396 KB |
Output is correct |