# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
423584 |
2021-06-11T09:55:50 Z |
Amylopectin |
RMQ (NOI17_rmq) |
C++14 |
|
64 ms |
4668 KB |
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int mxn = 4e5 + 10;
struct we
{
int fr,to,vaa;
};
bool cmp(const struct we &l,const struct we &r)
{
return l.vaa > r.vaa;
}
struct we a[mxn] = {};
int se[mxn] = {},fou,ofo,ta[mxn] = {},u[mxn] = {};
int fima(int l,int r)
{
if(l > r)
return l;
return r;
}
int fimi(int l,int r)
{
if(l < r)
return l;
return r;
}
int ins(int cl,int cr,int no,int tn)
{
if(cr < tn || cl > tn)
{
return 0;
}
if(cl == cr)
{
se[no] = 1;
return 0;
}
int mid = (cl+cr) / 2;
ins(cl,mid,no*2,tn);
ins(mid+1,cr,no*2+1,tn);
se[no] = se[no*2] + se[no*2+1];
return 0;
}
int fine(int cl,int cr,int no,int tn)
{
if(cr <= tn)
{
return 0;
}
if(se[no] == (cr-cl+1))
{
return 0;
}
if(cl == cr)
{
ofo = 1;
fou = cl;
return 0;
}
int mid = (cl+cr) / 2;
fine(cl,mid,no*2,tn);
if(ofo == 1)
{
return 0;
}
fine(mid+1,cr,no*2+1,tn);
return 0;
}
int main()
{
int i,j,n,m,ru = 0,be,cl,cr,bl,br,of = 0,fba;
scanf("%d %d",&n,&m);
for(i=0; i<m; i++)
{
scanf("%d %d %d",&a[i].fr,&a[i].to,&a[i].vaa);
}
sort(a,a+m,cmp);
fba = n-1;
for(i=0; i<n; i++)
{
ta[i] = -1;
}
while(ru < m)
{
be = ru;
cl = a[ru].fr;
cr = a[ru].to;
bl = cl;
br = cr;
ru ++;
while(ru < m && a[ru].vaa == a[be].vaa)
{
cl = fima(cl,a[ru].fr);
bl = fimi(bl,a[ru].fr);
cr = fimi(cr,a[ru].to);
br = fima(br,a[ru].to);
ru ++;
}
if(cl > cr)
{
of = 1;
break;
}
ofo = 0;
fine(0,n-1,1,cl-1);
if(ofo == 0 || fou > cr)
{
of = 1;
break;
}
ta[fou] = a[be].vaa;
u[a[be].vaa] = 1;
ins(0,n-1,1,fou);
for(j=bl; j<=br; j++)
{
if(ta[j] != -1)
{
ofo = 0;
fine(0,n-1,1,j);
if(ofo == 0)
{
break;
}
j = fou;
if(j > br)
{
break;
}
}
while(u[fba] == 1)
{
fba --;
}
ta[j] = fba;
u[fba] = 1;
if(fba < a[be].vaa)
{
of = 1;
break;
}
ins(0,n-1,1,j);
}
if(of == 1)
{
break;
}
}
if(of == 1)
{
for(i=0; i<n; i++)
{
printf("-1 ");
}
return 0;
}
for(i=0; i<n; i++)
{
if(ta[i] == -1)
{
while(u[fba] == 1)
{
fba --;
}
ta[i] = fba;
u[fba] = 1;
}
}
for(i=0; i<n; i++)
{
printf("%d ",ta[i]);
}
return 0;
}
Compilation message
rmq.cpp: In function 'int main()':
rmq.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%d %d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~
rmq.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
76 | scanf("%d %d %d",&a[i].fr,&a[i].to,&a[i].vaa);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
60 ms |
4668 KB |
Output is correct |
28 |
Correct |
54 ms |
4384 KB |
Output is correct |
29 |
Correct |
52 ms |
3868 KB |
Output is correct |
30 |
Correct |
58 ms |
4652 KB |
Output is correct |
31 |
Correct |
44 ms |
3560 KB |
Output is correct |
32 |
Correct |
64 ms |
3828 KB |
Output is correct |
33 |
Correct |
25 ms |
2392 KB |
Output is correct |
34 |
Correct |
21 ms |
1564 KB |
Output is correct |
35 |
Correct |
42 ms |
2740 KB |
Output is correct |
36 |
Correct |
36 ms |
2372 KB |
Output is correct |
37 |
Correct |
48 ms |
3144 KB |
Output is correct |
38 |
Correct |
4 ms |
716 KB |
Output is correct |
39 |
Correct |
34 ms |
2988 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
1 ms |
204 KB |
Output is correct |