# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
748681 |
2023-05-26T17:53:05 Z |
jamielim |
Meteors (POI11_met) |
C++14 |
|
943 ms |
28400 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int n,m,k;
int p[300005];
vi met[300005];
pair<ii,int> arr[300005];
int ans[300005];
ll fw[300005];
void upd(int x,int y,int v){
y++;
while(y<=m){
fw[y]-=v;
y+=(y&(-y));
}
while(x<=m){
fw[x]+=v;
x+=(x&(-x));
}
}
ll qry(int x){
ll ans=0;
while(x){
ans+=fw[x];
x-=(x&(-x));
}
return ans;
}
queue<pair<ii,vi> > q;
void pbs(){
pair<ii,vi> cur=q.front();q.pop();
int l=cur.fi.fi,r=cur.fi.se;
vi v=cur.se;
if(l>r)return;
if(l==0)memset(fw,0,sizeof(fw));
int mid=(l+r)/2;
for(int i=l;i<=mid;i++){
if(arr[i].fi.fi<=arr[i].fi.se)upd(arr[i].fi.fi,arr[i].fi.se,arr[i].se);
else{
upd(arr[i].fi.fi,m,arr[i].se);
upd(1,arr[i].fi.se,arr[i].se);
}
}
vector<int> v1,v2;
for(int i:v){
ll sum=0;
for(int j:met[i]){
sum+=qry(j);
if(sum>=p[i])break;
}
if(sum>=p[i]){
v1.pb(i);
ans[i]=mid;
}else{
v2.pb(i);
}
}
for(int i=mid+1;i<=r;i++){
if(arr[i].fi.fi<=arr[i].fi.se)upd(arr[i].fi.fi,arr[i].fi.se,arr[i].se);
else{
upd(arr[i].fi.fi,m,arr[i].se);
upd(1,arr[i].fi.se,arr[i].se);
}
}
q.push(mp(mp(l,mid-1),v1));
q.push(mp(mp(mid+1,r),v2));
}
int main(){
scanf("%d%d",&n,&m);
int o;
for(int i=1;i<=m;i++){
scanf("%d",&o);
met[o].pb(i);
}
for(int i=1;i<=n;i++)scanf("%d",&p[i]);
scanf("%d",&k);
for(int i=0;i<k;i++)scanf("%d%d%d",&arr[i].fi.fi,&arr[i].fi.se,&arr[i].se);
for(int i=1;i<=n;i++)ans[i]=k;
vector<int> v;
for(int i=1;i<=n;i++)v.pb(i);
q.push(mp(mp(0,k-1),v));
while(!q.empty())pbs();
for(int i=1;i<=n;i++){
if(ans[i]>=k)printf("NIE\n");
else printf("%d\n",ans[i]+1);
}
}
Compilation message
met.cpp: In function 'int main()':
met.cpp:89:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
met.cpp:92:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | scanf("%d",&o);
| ~~~~~^~~~~~~~~
met.cpp:95:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | for(int i=1;i<=n;i++)scanf("%d",&p[i]);
| ~~~~~^~~~~~~~~~~~
met.cpp:96:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
96 | scanf("%d",&k);
| ~~~~~^~~~~~~~~
met.cpp:97:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
97 | for(int i=0;i<k;i++)scanf("%d%d%d",&arr[i].fi.fi,&arr[i].fi.se,&arr[i].se);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
9684 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
58 ms |
11860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
93 ms |
12112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
87 ms |
11888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
11616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
943 ms |
28400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
890 ms |
27920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |