CSES - Siperia opettaa 2.0 - Results
Submission details
Task:Lines
Sender:Hansuzu
Submission time:2016-07-29 09:42:03 +0300
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.06 sdetails
#2ACCEPTED0.06 sdetails
#3ACCEPTED0.06 sdetails
#4ACCEPTED0.06 sdetails
#5ACCEPTED0.06 sdetails
#6ACCEPTED0.06 sdetails
#7ACCEPTED0.06 sdetails
#8ACCEPTED0.05 sdetails
#9ACCEPTED0.06 sdetails
#10ACCEPTED0.05 sdetails
#11ACCEPTED0.06 sdetails
#12ACCEPTED0.06 sdetails
#13ACCEPTED0.06 sdetails
#14ACCEPTED0.06 sdetails
#15ACCEPTED0.07 sdetails
#16ACCEPTED0.06 sdetails
#17ACCEPTED0.06 sdetails
#18ACCEPTED0.06 sdetails
#19ACCEPTED0.05 sdetails
#20ACCEPTED4.94 sdetails
#21ACCEPTED3.63 sdetails
#22ACCEPTED0.05 sdetails
#23ACCEPTED0.06 sdetails
#24ACCEPTED0.06 sdetails
#25ACCEPTED0.06 sdetails
#26ACCEPTED0.05 sdetails
#27ACCEPTED0.07 sdetails
#28ACCEPTED4.92 sdetails
#29ACCEPTED4.93 sdetails
#30ACCEPTED4.92 sdetails
#31ACCEPTED4.93 sdetails
#32ACCEPTED3.85 sdetails
#33ACCEPTED3.85 sdetails
#34ACCEPTED3.72 sdetails
#35ACCEPTED3.74 sdetails
#36ACCEPTED3.72 sdetails
#37ACCEPTED4.23 sdetails
#38ACCEPTED4.24 sdetails
#39ACCEPTED4.08 sdetails
#40ACCEPTED4.08 sdetails
#41ACCEPTED3.89 sdetails
#42ACCEPTED4.43 sdetails
#43ACCEPTED4.44 sdetails
#44ACCEPTED4.15 sdetails
#45ACCEPTED4.17 sdetails
#46ACCEPTED4.20 sdetails
#47ACCEPTED4.28 sdetails
#48ACCEPTED0.06 sdetails
#49ACCEPTED2.13 sdetails

Compiler report

input/code.cpp: In function 'long long int ibm(long double)':
input/code.cpp:62:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=0; i+1<xs.size(); i+=2){
                             ^
input/code.cpp:69:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i=0; i<pts.size(); ++i){
                            ^

Code

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#define MP make_pair
#define F first
#define S second
#define SZ (1<<18)
using namespace std;
int n;

long double cot(long double a){
  long double d=tan(a);
  if (d!=d) return 0;
  else return 1l/d;
}

int sp[SZ];

void put(int a){a+=SZ/2;
  sp[a]+=1;
  for (a/=2; a; a/=2) sp[a]=sp[2*a]+sp[2*a+1];
}

int get(int a, int b){a+=SZ/2; b+=SZ/2;
  int rv=0;
  while (a<b){
    if (a%2==1) rv+=sp[a++];
    if (b%2==0) rv+=sp[b--];
    a/=2; b/=2;
  }if (a==b) rv+=sp[a];
  return rv;
}


long double PI=-1;


int x[101010];
int y[101010];

vector<pair<pair<long double, long double>, int> > pts;

vector<long double> xs;
unordered_map<long double, int> ix;

long long ibm(long double ang){
  for (int i=0; i<SZ; i+=2) sp[i]=0, sp[i+1]=0;
  xs.clear();
  ix.clear();
  long double k=cot(ang);
  for (int i=0; i+1<n; i+=2){
    xs.push_back(pts[i].F.S=x[pts[i].S]-k*pts[i].F.F);
    xs.push_back(pts[i+1].F.S=x[pts[i+1].S]-k*pts[i+1].F.F);
  }
  if (n%2) xs.push_back(pts[n-1].F.S=x[pts[n-1].S]-k*pts[n-1].F.F);
  
  sort(xs.begin(), xs.end());
  
  for (int i=0; i+1<xs.size(); i+=2){
    ix[xs[i]]=i;
    ix[xs[i+1]]=i+1;
  }
  if (xs.size()%2) ix[xs[xs.size()-1]]=xs.size()-1;
  
  long long sm=0;
  for (int i=0; i<pts.size(); ++i){
    int ii=ix[pts[i].F.S];
    sm+=get(0, ii);;
    put(ii);
  }
  return sm;
}


long double bin(long long v){
  long double a=0;
  long double b=PI;
  for (int i=0; i<33; ++i){
    long double m=(a+b)/2;
    if (ibm(m)>=v) b=m;
    else a=m;
  }
  return (a+b)/2;
}

int main(){
  PI=acos(PI);
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> n;
  for (int i=0; i<n; ++i) cin >> x[i] >> y[i];
  for (int i=0; i<n; ++i) pts.push_back(MP(MP(y[i], x[i]), i));
  sort(pts.begin(), pts.end());
  long double a=bin(((long long)n*(n-1)/2+1)/2);
  long double b=bin(((long long)n*(n-1)/2+2)/2);
  cout << setprecision(20) << (a+b)/2 << "\n";
}

Test details

Test 1

Verdict: ACCEPTED

input
3
0 0
0 1
1 0

correct output
1.570796326361216

user output
1.5707963266120318594

Test 2

Verdict: ACCEPTED

input
4
0 0
0 1
1 0
1 1

correct output
1.178097245010921

user output
1.1780972449133077045

Test 3

Verdict: ACCEPTED

input
3
0 0
0 1000000000
1 0

correct output
1.570796326361216

user output
1.5707963266120318594

Test 4

Verdict: ACCEPTED

input
3
0 0
1 0
2 0

correct output
0.000000001000000

user output
1.8286475990839496013e-10

Test 5

Verdict: ACCEPTED

input
3
5 -2
-5 -4
-4 4

correct output
1.446441331885909

user output
1.4464413322359382918

Test 6

Verdict: ACCEPTED

input
3
0 4
-3 -1
-4 4

correct output
1.030376826373869

user output
1.0303768265306605104

Test 7

Verdict: ACCEPTED

input
3
0 -1
3 -3
-4 1

correct output
2.622446539330037

user output
2.6224465393789041911

Test 8

Verdict: ACCEPTED

input
3
-5 -3
-3 0
3 5

correct output
0.785398163226945

user output
0.78539816321458354967

Test 9

Verdict: ACCEPTED

input
3
-5 3
-1 -2
5 -3

correct output
2.601173153316589

user output
2.6011731533255571299

Test 10

Verdict: ACCEPTED

input
3
-2 0
-3 3
1 -2

correct output
2.245537268920354

user output
2.2455372690349160612

Test 11

Verdict: ACCEPTED

input
3
-2 -1
-3 2
1 -3

correct output
2.245537268920354

user output
2.2455372690349160612

Test 12

Verdict: ACCEPTED

input
3
3 -3
1 -1
0 2

correct output
2.111215826897042

user output
2.111215827059132728

Test 13

Verdict: ACCEPTED

input
3
0 -3
2 0
-3 0

correct output
0.982793723190022

user output
0.98279372340627842977

Test 14

Verdict: ACCEPTED

input
5
1 -3
0 -3
2 2
-3 3
...

correct output
1.802620131078459

user output
1.8026201312097265503

Test 15

Verdict: ACCEPTED

input
5
-3 -2
2 -2
1 -2
1 -1
...

correct output
0.582952270226021

user output
0.58295227023339928453

Test 16

Verdict: ACCEPTED

input
50
-3 -3
5 -5
0 -5
-5 2
...

correct output
1.570796326361216

user output
1.5707963266120318594

Test 17

Verdict: ACCEPTED

input
50
4 4
2 1
-2 1
5 -3
...

correct output
1.570796326361216

user output
1.5707963266120318594

Test 18

Verdict: ACCEPTED

input
50
442366208 279138083
-184561367 198541207
823405894 -564413219
114448377 768487602
...

correct output
1.418644093993140

user output
1.4186440940951085169

Test 19

Verdict: ACCEPTED

input
50
816110770 -689704132
494898871 528573081
166680604 515808141
582252599 -643183741
...

correct output
1.656117102112052

user output
1.6561171022333774722

Test 20

Verdict: ACCEPTED

input
100000
-150948623 524048786
15875754 245984095
-680102685 -996037369
-312145822 195412711
...

correct output
1.567645716335110

user output
1.5676457163821838193

Test 21

Verdict: ACCEPTED

input
80000
-587936709 929197030
816737335 627407406
-637765108 -922560549
195018519 -727622801
...

correct output
1.564802980555181

user output
1.5648029809194127509

Test 22

Verdict: ACCEPTED

input
4
-3 -4
-5 -4
2 -1
-3 -2

correct output
0.472655643272179

user output
0.47265564320473469942

Test 23

Verdict: ACCEPTED

input
10
-3 -7
-5 9
-1 6
-8 2
...

correct output
1.703347858852173

user output
1.7033478589782614189

Test 24

Verdict: ACCEPTED

input
3
-1000000000 0
1000000000 0
1000000000 1

correct output
0.000000001000000

user output
5.4859427972518488042e-10

Test 25

Verdict: ACCEPTED

input
3
-1000000000 0
1000000000 0
1000000000 3

correct output
0.000000001500000

user output
1.6457828391755546412e-09

Test 26

Verdict: ACCEPTED

input
3
-1000000000 0
1000000000 0
1000000000 2

correct output
0.000000001000000

user output
9.1432379954197480066e-10

Test 27

Verdict: ACCEPTED

input
3
-1000000000 0
1000000000 0
1000000000 5

correct output
0.000000002500000

user output
2.3772418788091344817e-09

Test 28

Verdict: ACCEPTED

input
99996
733545312 -23346396
-795397579 -404874879
-503473099 346027613
-271528713 -541325642
...

correct output
1.570738488959610

user output
1.5707384890485794729

Test 29

Verdict: ACCEPTED

input
100000
-569987404 -522495344
77828992 -662077558
-751319779 -938754614
676233529 -390989412
...

correct output
1.572402491568657

user output
1.5724024919838380202

Test 30

Verdict: ACCEPTED

input
100000
671546196 228818010
-138266629 -168233695
-323825826 334459800
216860157 -420208747
...

correct output
1.567256816862458

user output
1.5672568169829628362

Test 31

Verdict: ACCEPTED

input
99999
720191241 515523232
-327632871 233538461
-512554358 300865696
945279418 -948967513
...

correct output
1.574006709521912

user output
1.5740067094802216367

Test 32

Verdict: ACCEPTED

input
100000
984248694 0
614763735 0
203383912 0
862359296 0
...

correct output
0.000000001000000

user output
1.8286475990839496013e-10

Test 33

Verdict: ACCEPTED

input
100000
57050460 0
-375026139 0
-820386623 0
-99980585 0
...

correct output
0.000000001000000

user output
1.8286475990839496013e-10

Test 34

Verdict: ACCEPTED

input
100000
876809794 -438404747
394286770 -197143235
-367448514 183724407
-383434666 191717483
...

correct output
2.677945044551917

user output
2.6779450445772686163

Test 35

Verdict: ACCEPTED

input
100000
-154037240 1510270
362293900 -3551800
2089162 -20381
-717258188 7032044
...

correct output
3.131789046110464

user output
3.1317890461444780983

Test 36

Verdict: ACCEPTED

input
100000
412444110 -457155
-684758612 759256
479239014 -531207
390243184 -432542
...

correct output
3.140484006593894

user output
3.1404840065416222486

Test 37

Verdict: ACCEPTED

input
100000
796270214 1
-951846498 0
217668093 -2
-154910102 0
...

correct output
0.000000007305530

user output
7.131725636427403445e-09

Test 38

Verdict: ACCEPTED

input
100000
-253706492 2
-226875621 2
362330838 2
-795605493 2
...

correct output
0.000000007263216

user output
7.131725636427403445e-09

Test 39

Verdict: ACCEPTED

input
100000
934702833 -467351271
-131493362 65746831
913964656 -456982181
627793697 -313896700
...

correct output
2.677945044551917

user output
2.6779450445772686163

Test 40

Verdict: ACCEPTED

input
100000
-668200264 6551087
86496002 -847902
-871928849 8548421
-136205907 1335452
...

correct output
3.131789046110464

user output
3.1317890461444780983

Test 41

Verdict: ACCEPTED

input
100000
595966829 -660620
-51714261 57430
991615602 -1099248
-863804708 957752
...

correct output
3.140484006593894

user output
3.1404840065416222486

Test 42

Verdict: ACCEPTED

input
100000
140 20
2 -114
152 -60
-82 123
...

correct output
1.566291852418795

user output
1.5662918526283241894

Test 43

Verdict: ACCEPTED

input
100000
-79 -25
-117 178
-70 221
-291 71
...

correct output
1.570796326361216

user output
1.5707963266120318594

Test 44

Verdict: ACCEPTED

input
100000
74068734 -67184987
-73589858 -67709177
-63969660 -76862751
-90718064 42074133
...

correct output
1.570780621042227

user output
1.5707806210892623669

Test 45

Verdict: ACCEPTED

input
99999
400813117 -805821844
874374859 -213233688
33553856 899374304
853659607 285070648
...

correct output
1.570796326361216

user output
1.5707963266120318594

Test 46

Verdict: ACCEPTED

input
99999
99957306 -2955708
-9788208 99519803
-31843316 -94794095
-62763244 -77850073
...

correct output
1.570780617572780

user output
1.5707806174319671686

Test 47

Verdict: ACCEPTED

input
100000
-94881770 31583126
44754159 -89425361
87229737 -48896753
77708105 62941177
...

correct output
1.570780277133298

user output
1.5707802773035137392

Test 48

Verdict: ACCEPTED

input
201
-100 10000
-99 9801
-98 9604
-97 9409
...

correct output
1.565420034260210

user output
1.5654200346450343615

Test 49

Verdict: ACCEPTED

input
62003
-31001 961062001
-31000 961000000
-30999 960938001
-30998 960876004
...

correct output
1.570780133151250

user output
1.5707801332060829313