CSES - Putka Open 2015 – finaali - Results
Submission details
Task:Ravintola
Sender:
Submission time:2015-12-20 14:33:37 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.05 s1details
#20.05 s1details
#30.06 s1details
#40.05 s1details
#5--1details
#6--2details
#7--2details
#80.06 s2details
#90.04 s2details
#100.04 s2details
#110.81 s3details
#12--3details
#130.81 s3details
#140.84 s3details
#150.79 s3details

Compiler report

input/code.cpp: In function 'int64_t push(std::vector<std::pair<long int, long int> >&, int64_t)':
input/code.cpp:29:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
input/code.cpp: In function 'int64_t mark(std::vector<std::pair<long int, long int> >&, int64_t, int64_t)':
input/code.cpp:124:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
input/code.cpp: In function 'int main()':
input/code.cpp:151:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while(M <= 2*coords.size()) {
           ^

Code

#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
typedef pair<int64_t,int64_t> P;
struct T {
int64_t a, b, g;
};
bool operator<(const T& t1, const T& t2) {
if(t1.b < t2.b) return true;
if(t1.b == t2.b && t1.a < t2.a) return true;
if(t1.b == t2.b && t1.a == t2.a && t1.g < t2.g) return true;
return false;
}
int64_t M=1;
int64_t push(vector<pair<int64_t,int64_t>> &spuu, int64_t r) {
spuu[2*r].first+=spuu[r].first;
spuu[2*r].second+=spuu[r].first;
spuu[2*r+1].first+=spuu[r].first;
spuu[2*r+1].second+=spuu[r].first;
spuu[r].first=0;
}
int64_t left(int64_t a) {
while(a < M) {
a*=2;
}
return a;
}
int64_t right(int64_t b) {
while(b < M) {
b=2*b+1;
}
return b;
}
int64_t leftmax(int64_t a) {
return right(2*a);
}
int64_t rightmin(int64_t b) {
return left(2*b+1);
}
int64_t getmax(vector<pair<int64_t,int64_t>> &spuu, int64_t a, int64_t b) {
a+=M;
b+=M;
int64_t r1=1;
while(left(r1) != a) {
push(spuu, r1);
if(leftmax(r1) >= a) r1*=2;
else r1=2*r1+1;
}
int64_t r2=1;
while(right(r2) != b) {
push(spuu, r2);
if(rightmin(r2) <= b) r2=2*r2+1;
else r2=2*r2;
}
while(r1 != r2) {
if(r1 > r2) {
r1=(r1+1)/2;
} else {
r2=(r2-1)/2;
}
}
return spuu[r1].second;
}
int64_t mark(vector<pair<int64_t,int64_t>> &spuu, int64_t a, int64_t b) {
a+=M;
b+=M;
int64_t r1=1;
while(left(r1) != a) {
push(spuu, r1);
if(leftmax(r1) >= a) r1*=2;
else r1=2*r1+1;
}
int64_t r2=1;
while(right(r2) != b) {
push(spuu, r2);
if(rightmin(r2) <= b) r2=2*r2+1;
else r2=2*r2;
}
while(a <= b) {
/*cout << "a: " << a << endl;
cout << "b: " << b << endl;*/
if(a%2 == 1) {
spuu[a].first++;
if(2*a < 2*M) {
spuu[a].second=max(spuu[2*a].second+1, spuu[2*a+1].second+1);
} else {
spuu[a].second++;
}
}
if(b%2 == 0) {
spuu[b].first++;
if(2*b < 2*M) {
spuu[b].second=max(spuu[2*b].second+1, spuu[2*b+1].second+1);
} else {
spuu[b].second++;
}
}
a=(a+1)/2;
b=(b-1)/2;
}
while(a >= 1) {
spuu[a].second=max(spuu[2*a].second, spuu[2*a+1].second);
a/=2;
}
while(b >= 1) {
spuu[b].second=max(spuu[2*b].second, spuu[2*b+1].second);
b/=2;
}
}
int main(void)
{
int64_t n;
cin >> n;
vector<T> times(n);
set<int64_t> foo;
for(int64_t i=0;i<n;i++) {
cin >> times[i].a >> times[i].b;
times[i].g=i;
foo.insert(times[i].a);
foo.insert(times[i].b);
}
sort(times.begin(),times.end());
map<int64_t,int64_t> coords;
map<int64_t,int64_t> invcoords;
int64_t bar=0;
for(auto s: foo) {
invcoords[bar]=s;
coords[s]=bar++;
}
while(M <= 2*coords.size()) {
M*=2;
}
M/=2;
vector<pair<int64_t,int64_t>> spuu(2*M);
map<int64_t,int64_t> moves;
int64_t maxm=0;
for(int64_t i=0;i<n;i++) {
// cout << "Marking: " << coords[times[i].a] << "(" << times[i].a << ") to " << coords[times[i].b]-1 << "(" << times[i].b << ")"<< endl;
mark(spuu, coords[times[i].a], coords[times[i].b]-1);
/*for(int64_t j=0;j<spuu.size();j++) {
cout << j << ": " << spuu[j].first << "," << spuu[j].second << endl;
}*/
int64_t mym=getmax(spuu, coords[times[i].a], coords[times[i].b]-1);
moves[times[i].g]=mym;
maxm=max(mym,maxm);
}
cout << maxm << '\n';
for(int64_t i=0;i<n;i++) {
cout << moves[i] << '\n';
}
return 0;
}

Test details

Test 1

Group: 1

Verdict:

input
10
78 83
61 70
95 100
84 100
...

correct output
6
5
5
2
1
...

user output
6
1
0
6
1
...

Test 2

Group: 1

Verdict:

input
10
90 98
99 100
96 100
3 47
...

correct output
4
1
1
3
1
...

user output
3
3
3
3
1
...

Test 3

Group: 1

Verdict:

input
10
65 87
89 97
32 53
53 73
...

correct output
5
5
4
3
3
...

user output
4
2
4
0
1
...

Test 4

Group: 1

Verdict:

input
10
54 68
50 60
87 89
85 98
...

correct output
6
6
3
4
1
...

user output
4
2
0
3
3
...

Test 5

Group: 1

Verdict:

input
10
53 54
41 47
56 68
6 23
...

correct output
5
2
2
2
2
...

user output
(empty)

Test 6

Group: 2

Verdict:

input
1000
421639537 911563318
736166797 959945771
397431507 584367626
330835287 620406496
...

correct output
358
264
215
218
262
...

user output
(empty)

Test 7

Group: 2

Verdict:

input
1000
452773897 489658400
791565174 873685909
837939163 961670907
54444659 861374731
...

correct output
393
181
151
140
63
...

user output
(empty)

Test 8

Group: 2

Verdict:

input
1000
689073468 881081127
613328959 683799585
688380485 930935455
629559449 915788743
...

correct output
388
115
358
93
170
...

user output
353
229
14
158
250
...

Test 9

Group: 2

Verdict:

input
1000
376658209 496021591
750793088 930681206
293307485 666877615
774206996 816529147
...

correct output
368
287
36
225
114
...

user output
333
50
170
129
22
...

Test 10

Group: 2

Verdict:

input
1000
273998160 725204323
241875005 614630291
765984835 939309031
345615468 836277449
...

correct output
384
240
215
156
163
...

user output
348
121
77
183
191
...

Test 11

Group: 3

Verdict:

input
100000
784035755 893627685
78761690 459329957
877042231 976087228
479438596 515807337
...

correct output
36779
4699
7608
7073
23546
...

user output
35899
13293
0
13536
7486
...

Test 12

Group: 3

Verdict:

input
100000
952007928 998571741
60494193 790262572
37935588 450716710
518464251 658961939
...

correct output
36979
5145
5964
3813
17811
...

user output
(empty)

Test 13

Group: 3

Verdict:

input
100000
195552215 647391707
698053972 908728728
923590842 940850158
17166936 129136741
...

correct output
36760
17563
24436
3901
1722
...

user output
36068
12351
28207
30431
0
...

Test 14

Group: 3

Verdict:

input
100000
792681664 892304133
442916094 984949977
880260482 922213143
417012279 978533731
...

correct output
36633
5062
11088
8773
23538
...

user output
35660
12741
33959
5112
33207
...

Test 15

Group: 3

Verdict:

input
100000
662244341 835857878
88360474 126816291
245452241 989480216
32665049 226410123
...

correct output
36920
28994
8379
21303
3304
...

user output
36090
17728
201
34917
0
...