# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
20449 |
2017-02-11T15:04:18 Z |
I_forgot_password(#50, mAng0) |
초음속철도 (OJUZ11_rail) |
C++ |
|
2813 ms |
36748 KB |
#include<bits/stdc++.h>
#define je 1000000007
#define pp 524288
using namespace std;
pair<int,int> train[200001];
vector<int> cnt;
map<int,int> dict;
long long sum[1048576];
int div2[1048576];
int can;
int gae=0;
long long jegop(int left){
if(!left) return 1;
else if(left & 1){
long long res = jegop(left / 2);
return (res * res * 2) % je;
}else{
long long res = jegop(left / 2);
return res * res % je;
}
}
void segPlus(int place,long long what,int ss,int ee,int idx){
//printf("segPlus: %d %lld %d %d %d ?%lld %d\n",place,what,ss,ee,idx,sum[idx],div2[idx]);
if(div2[idx]){
sum[idx] = sum[idx] * jegop(je - 1 - div2[idx]) % je;
}
sum[idx] = (sum[idx] + what) % je;
if(ss==ee){
div2[idx] = 0; return;
}
div2[idx*2] += div2[idx]; div2[idx*2+1] += div2[idx]; div2[idx] = 0;
int mid = (ss+ee)/2;
if(place <= mid){
segPlus(place,what,ss,mid,idx*2);
}else{
segPlus(place,what,mid+1,ee,idx*2+1);
}
}
long long getsum(int from,int to,int ss,int ee,int idx){
//printf("getsum: %d %d %d %d %d ?%lld %d\n",from,to,ss,ee,idx,sum[idx],div2[idx]);
long long retval,new_minus;
if(div2[idx]){
sum[idx] = sum[idx] * jegop(je - 1 - div2[idx]) % je;
}
if(ss!=ee){
div2[idx*2] += div2[idx];
div2[idx*2+1] += div2[idx];
div2[idx] = 0;
}else{
div2[idx] = 0;
}
if(from == ss && to == ee){
div2[idx]++;
return sum[idx];
}else{
int mid = (ss+ee)/2;
if(to <= mid){
retval = getsum(from,to,ss,mid,idx*2);
}else if(from > mid){
retval = getsum(from,to,mid+1,ee,idx*2+1);
}else{
retval = (getsum(from,mid,ss,mid,idx*2) + getsum(mid+1,to,mid+1,ee,idx*2+1)) % je;
}
if(retval%2) new_minus = (retval + je) / 2;
else new_minus = (retval) / 2;
sum[idx] = (sum[idx] + je - new_minus) % je;
return retval;
}
}
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++){
scanf("%d%d",&(train[i].first),&(train[i].second));
cnt.push_back(train[i].first);
cnt.push_back(train[i].second);
}
cnt.push_back(-1);
sort(cnt.begin(),cnt.end());
int prv = -1;
if(cnt[1] != 1 || cnt[(int)cnt.size() - 1] != n){
printf("0");
return 0;
}
for(int i=1;i<cnt.size();i++){
if(cnt[i-1] != cnt[i]){
dict[cnt[i]] = gae++;
}
}
sort(train,train+m);
can = 0;
segPlus(0,1,0,pp-1,1);
for(int j=0;j<m;j++){
int from = dict[train[j].first];
int to = dict[train[j].second];
//printf("%d, %d\n",from,to);
if(can < from){
printf("%d",0);
return 0;
}
can = max(can,to);
long long retval = getsum(from,to-1,0,pp-1,1);
if(retval%2==1) retval = (retval + je) / 2;
else retval = retval / 2;
//printf("%lld\n",retval);
segPlus(to,retval,0,pp-1,1);
}
segPlus(gae-1,0,0,pp-1,1);
if(can == gae-1) printf("%lld",getsum(gae-1,gae-1,0,pp-1,1) * jegop(m) % je);
else printf("0");
}
Compilation message
rail.cpp: In function 'int main()':
rail.cpp:90:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1;i<cnt.size();i++){
^
rail.cpp:85:9: warning: unused variable 'prv' [-Wunused-variable]
int prv = -1;
^
rail.cpp:77:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&m);
^
rail.cpp:79:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&(train[i].first),&(train[i].second));
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
15876 KB |
Output is correct |
2 |
Correct |
0 ms |
15876 KB |
Output is correct |
3 |
Correct |
0 ms |
15876 KB |
Output is correct |
4 |
Correct |
0 ms |
15876 KB |
Output is correct |
5 |
Correct |
0 ms |
15876 KB |
Output is correct |
6 |
Correct |
0 ms |
15876 KB |
Output is correct |
7 |
Correct |
0 ms |
15876 KB |
Output is correct |
8 |
Correct |
0 ms |
15876 KB |
Output is correct |
9 |
Correct |
0 ms |
15876 KB |
Output is correct |
10 |
Correct |
0 ms |
15876 KB |
Output is correct |
11 |
Correct |
0 ms |
15876 KB |
Output is correct |
12 |
Correct |
0 ms |
15876 KB |
Output is correct |
13 |
Correct |
0 ms |
15876 KB |
Output is correct |
14 |
Correct |
0 ms |
15876 KB |
Output is correct |
15 |
Correct |
0 ms |
15876 KB |
Output is correct |
16 |
Correct |
0 ms |
15876 KB |
Output is correct |
17 |
Correct |
0 ms |
15876 KB |
Output is correct |
18 |
Correct |
0 ms |
15876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
15876 KB |
Output is correct |
2 |
Correct |
0 ms |
15876 KB |
Output is correct |
3 |
Correct |
0 ms |
15876 KB |
Output is correct |
4 |
Correct |
0 ms |
15876 KB |
Output is correct |
5 |
Correct |
0 ms |
15876 KB |
Output is correct |
6 |
Correct |
0 ms |
15876 KB |
Output is correct |
7 |
Correct |
0 ms |
15876 KB |
Output is correct |
8 |
Correct |
0 ms |
15876 KB |
Output is correct |
9 |
Correct |
0 ms |
15876 KB |
Output is correct |
10 |
Correct |
0 ms |
15876 KB |
Output is correct |
11 |
Correct |
0 ms |
15876 KB |
Output is correct |
12 |
Correct |
0 ms |
15876 KB |
Output is correct |
13 |
Correct |
0 ms |
15876 KB |
Output is correct |
14 |
Correct |
0 ms |
15876 KB |
Output is correct |
15 |
Correct |
0 ms |
15876 KB |
Output is correct |
16 |
Correct |
0 ms |
15876 KB |
Output is correct |
17 |
Correct |
0 ms |
15876 KB |
Output is correct |
18 |
Correct |
0 ms |
15876 KB |
Output is correct |
19 |
Correct |
0 ms |
15876 KB |
Output is correct |
20 |
Correct |
0 ms |
15876 KB |
Output is correct |
21 |
Correct |
0 ms |
15876 KB |
Output is correct |
22 |
Correct |
0 ms |
15876 KB |
Output is correct |
23 |
Correct |
0 ms |
15876 KB |
Output is correct |
24 |
Correct |
0 ms |
15876 KB |
Output is correct |
25 |
Correct |
0 ms |
15876 KB |
Output is correct |
26 |
Correct |
0 ms |
15876 KB |
Output is correct |
27 |
Correct |
0 ms |
15876 KB |
Output is correct |
28 |
Correct |
0 ms |
15876 KB |
Output is correct |
29 |
Correct |
0 ms |
15876 KB |
Output is correct |
30 |
Correct |
0 ms |
15876 KB |
Output is correct |
31 |
Correct |
0 ms |
15876 KB |
Output is correct |
32 |
Correct |
0 ms |
15876 KB |
Output is correct |
33 |
Correct |
0 ms |
15876 KB |
Output is correct |
34 |
Correct |
0 ms |
15876 KB |
Output is correct |
35 |
Correct |
0 ms |
15876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
15876 KB |
Output is correct |
2 |
Correct |
0 ms |
15876 KB |
Output is correct |
3 |
Correct |
0 ms |
15876 KB |
Output is correct |
4 |
Correct |
13 ms |
16016 KB |
Output is correct |
5 |
Correct |
929 ms |
20512 KB |
Output is correct |
6 |
Correct |
589 ms |
35164 KB |
Output is correct |
7 |
Correct |
553 ms |
34900 KB |
Output is correct |
8 |
Correct |
0 ms |
15876 KB |
Output is correct |
9 |
Correct |
539 ms |
33844 KB |
Output is correct |
10 |
Correct |
546 ms |
34768 KB |
Output is correct |
11 |
Correct |
376 ms |
18564 KB |
Output is correct |
12 |
Correct |
549 ms |
35164 KB |
Output is correct |
13 |
Correct |
549 ms |
34768 KB |
Output is correct |
14 |
Correct |
216 ms |
19032 KB |
Output is correct |
15 |
Correct |
333 ms |
27376 KB |
Output is correct |
16 |
Correct |
213 ms |
19032 KB |
Output is correct |
17 |
Correct |
549 ms |
35164 KB |
Output is correct |
18 |
Correct |
583 ms |
35164 KB |
Output is correct |
19 |
Correct |
583 ms |
32656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
15876 KB |
Output is correct |
2 |
Correct |
0 ms |
15876 KB |
Output is correct |
3 |
Correct |
0 ms |
15876 KB |
Output is correct |
4 |
Correct |
0 ms |
15876 KB |
Output is correct |
5 |
Correct |
0 ms |
15876 KB |
Output is correct |
6 |
Correct |
0 ms |
15876 KB |
Output is correct |
7 |
Correct |
0 ms |
15876 KB |
Output is correct |
8 |
Correct |
0 ms |
15876 KB |
Output is correct |
9 |
Correct |
0 ms |
15876 KB |
Output is correct |
10 |
Correct |
0 ms |
15876 KB |
Output is correct |
11 |
Correct |
0 ms |
15876 KB |
Output is correct |
12 |
Correct |
0 ms |
15876 KB |
Output is correct |
13 |
Correct |
0 ms |
15876 KB |
Output is correct |
14 |
Correct |
0 ms |
15876 KB |
Output is correct |
15 |
Correct |
0 ms |
15876 KB |
Output is correct |
16 |
Correct |
0 ms |
15876 KB |
Output is correct |
17 |
Correct |
0 ms |
15876 KB |
Output is correct |
18 |
Correct |
0 ms |
15876 KB |
Output is correct |
19 |
Correct |
0 ms |
15876 KB |
Output is correct |
20 |
Correct |
0 ms |
15876 KB |
Output is correct |
21 |
Correct |
0 ms |
15876 KB |
Output is correct |
22 |
Correct |
0 ms |
15876 KB |
Output is correct |
23 |
Correct |
0 ms |
15876 KB |
Output is correct |
24 |
Correct |
0 ms |
15876 KB |
Output is correct |
25 |
Correct |
0 ms |
15876 KB |
Output is correct |
26 |
Correct |
0 ms |
15876 KB |
Output is correct |
27 |
Correct |
0 ms |
15876 KB |
Output is correct |
28 |
Correct |
0 ms |
15876 KB |
Output is correct |
29 |
Correct |
0 ms |
15876 KB |
Output is correct |
30 |
Correct |
0 ms |
15876 KB |
Output is correct |
31 |
Correct |
0 ms |
15876 KB |
Output is correct |
32 |
Correct |
0 ms |
15876 KB |
Output is correct |
33 |
Correct |
0 ms |
15876 KB |
Output is correct |
34 |
Correct |
0 ms |
15876 KB |
Output is correct |
35 |
Correct |
0 ms |
15876 KB |
Output is correct |
36 |
Correct |
39 ms |
16412 KB |
Output is correct |
37 |
Correct |
33 ms |
16280 KB |
Output is correct |
38 |
Correct |
26 ms |
16148 KB |
Output is correct |
39 |
Correct |
6 ms |
16016 KB |
Output is correct |
40 |
Correct |
6 ms |
16148 KB |
Output is correct |
41 |
Correct |
0 ms |
16016 KB |
Output is correct |
42 |
Correct |
43 ms |
16412 KB |
Output is correct |
43 |
Correct |
0 ms |
15876 KB |
Output is correct |
44 |
Correct |
19 ms |
16280 KB |
Output is correct |
45 |
Correct |
6 ms |
16016 KB |
Output is correct |
46 |
Correct |
16 ms |
16148 KB |
Output is correct |
47 |
Correct |
29 ms |
16148 KB |
Output is correct |
48 |
Correct |
26 ms |
16148 KB |
Output is correct |
49 |
Correct |
13 ms |
16016 KB |
Output is correct |
50 |
Correct |
13 ms |
16016 KB |
Output is correct |
51 |
Correct |
9 ms |
16016 KB |
Output is correct |
52 |
Correct |
9 ms |
16008 KB |
Output is correct |
53 |
Correct |
3 ms |
16016 KB |
Output is correct |
54 |
Correct |
16 ms |
16016 KB |
Output is correct |
55 |
Correct |
3 ms |
16016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
15876 KB |
Output is correct |
2 |
Correct |
0 ms |
15876 KB |
Output is correct |
3 |
Correct |
0 ms |
15876 KB |
Output is correct |
4 |
Correct |
0 ms |
15876 KB |
Output is correct |
5 |
Correct |
0 ms |
15876 KB |
Output is correct |
6 |
Correct |
0 ms |
15876 KB |
Output is correct |
7 |
Correct |
0 ms |
15876 KB |
Output is correct |
8 |
Correct |
0 ms |
15876 KB |
Output is correct |
9 |
Correct |
0 ms |
15876 KB |
Output is correct |
10 |
Correct |
0 ms |
15876 KB |
Output is correct |
11 |
Correct |
0 ms |
15876 KB |
Output is correct |
12 |
Correct |
0 ms |
15876 KB |
Output is correct |
13 |
Correct |
0 ms |
15876 KB |
Output is correct |
14 |
Correct |
0 ms |
15876 KB |
Output is correct |
15 |
Correct |
0 ms |
15876 KB |
Output is correct |
16 |
Correct |
0 ms |
15876 KB |
Output is correct |
17 |
Correct |
0 ms |
15876 KB |
Output is correct |
18 |
Correct |
0 ms |
15876 KB |
Output is correct |
19 |
Correct |
0 ms |
15876 KB |
Output is correct |
20 |
Correct |
0 ms |
15876 KB |
Output is correct |
21 |
Correct |
0 ms |
15876 KB |
Output is correct |
22 |
Correct |
0 ms |
15876 KB |
Output is correct |
23 |
Correct |
0 ms |
15876 KB |
Output is correct |
24 |
Correct |
0 ms |
15876 KB |
Output is correct |
25 |
Correct |
0 ms |
15876 KB |
Output is correct |
26 |
Correct |
0 ms |
15876 KB |
Output is correct |
27 |
Correct |
0 ms |
15876 KB |
Output is correct |
28 |
Correct |
0 ms |
15876 KB |
Output is correct |
29 |
Correct |
0 ms |
15876 KB |
Output is correct |
30 |
Correct |
0 ms |
15876 KB |
Output is correct |
31 |
Correct |
0 ms |
15876 KB |
Output is correct |
32 |
Correct |
0 ms |
15876 KB |
Output is correct |
33 |
Correct |
0 ms |
15876 KB |
Output is correct |
34 |
Correct |
0 ms |
15876 KB |
Output is correct |
35 |
Correct |
0 ms |
15876 KB |
Output is correct |
36 |
Correct |
0 ms |
15876 KB |
Output is correct |
37 |
Correct |
0 ms |
15876 KB |
Output is correct |
38 |
Correct |
0 ms |
15876 KB |
Output is correct |
39 |
Correct |
13 ms |
16016 KB |
Output is correct |
40 |
Correct |
929 ms |
20512 KB |
Output is correct |
41 |
Correct |
589 ms |
35164 KB |
Output is correct |
42 |
Correct |
553 ms |
34900 KB |
Output is correct |
43 |
Correct |
0 ms |
15876 KB |
Output is correct |
44 |
Correct |
539 ms |
33844 KB |
Output is correct |
45 |
Correct |
546 ms |
34768 KB |
Output is correct |
46 |
Correct |
376 ms |
18564 KB |
Output is correct |
47 |
Correct |
549 ms |
35164 KB |
Output is correct |
48 |
Correct |
549 ms |
34768 KB |
Output is correct |
49 |
Correct |
216 ms |
19032 KB |
Output is correct |
50 |
Correct |
333 ms |
27376 KB |
Output is correct |
51 |
Correct |
213 ms |
19032 KB |
Output is correct |
52 |
Correct |
549 ms |
35164 KB |
Output is correct |
53 |
Correct |
583 ms |
35164 KB |
Output is correct |
54 |
Correct |
583 ms |
32656 KB |
Output is correct |
55 |
Correct |
39 ms |
16412 KB |
Output is correct |
56 |
Correct |
33 ms |
16280 KB |
Output is correct |
57 |
Correct |
26 ms |
16148 KB |
Output is correct |
58 |
Correct |
6 ms |
16016 KB |
Output is correct |
59 |
Correct |
6 ms |
16148 KB |
Output is correct |
60 |
Correct |
0 ms |
16016 KB |
Output is correct |
61 |
Correct |
43 ms |
16412 KB |
Output is correct |
62 |
Correct |
0 ms |
15876 KB |
Output is correct |
63 |
Correct |
19 ms |
16280 KB |
Output is correct |
64 |
Correct |
6 ms |
16016 KB |
Output is correct |
65 |
Correct |
16 ms |
16148 KB |
Output is correct |
66 |
Correct |
29 ms |
16148 KB |
Output is correct |
67 |
Correct |
26 ms |
16148 KB |
Output is correct |
68 |
Correct |
13 ms |
16016 KB |
Output is correct |
69 |
Correct |
13 ms |
16016 KB |
Output is correct |
70 |
Correct |
9 ms |
16016 KB |
Output is correct |
71 |
Correct |
9 ms |
16008 KB |
Output is correct |
72 |
Correct |
3 ms |
16016 KB |
Output is correct |
73 |
Correct |
16 ms |
16016 KB |
Output is correct |
74 |
Correct |
3 ms |
16016 KB |
Output is correct |
75 |
Correct |
2813 ms |
36748 KB |
Output is correct |
76 |
Correct |
1719 ms |
30280 KB |
Output is correct |
77 |
Correct |
996 ms |
19032 KB |
Output is correct |
78 |
Correct |
219 ms |
19032 KB |
Output is correct |
79 |
Correct |
89 ms |
19032 KB |
Output is correct |
80 |
Correct |
2739 ms |
36748 KB |
Output is correct |
81 |
Correct |
36 ms |
16148 KB |
Output is correct |
82 |
Correct |
2383 ms |
34636 KB |
Output is correct |
83 |
Correct |
203 ms |
19032 KB |
Output is correct |
84 |
Correct |
1866 ms |
31996 KB |
Output is correct |
85 |
Correct |
1873 ms |
27376 KB |
Output is correct |
86 |
Correct |
1769 ms |
27376 KB |
Output is correct |
87 |
Correct |
383 ms |
19032 KB |
Output is correct |
88 |
Correct |
336 ms |
19032 KB |
Output is correct |
89 |
Correct |
2676 ms |
36748 KB |
Output is correct |
90 |
Correct |
2729 ms |
36748 KB |
Output is correct |
91 |
Correct |
2763 ms |
36748 KB |
Output is correct |
92 |
Correct |
106 ms |
19032 KB |
Output is correct |
93 |
Correct |
1813 ms |
27244 KB |
Output is correct |
94 |
Correct |
2753 ms |
36748 KB |
Output is correct |
95 |
Correct |
2789 ms |
36748 KB |
Output is correct |