-
Notifications
You must be signed in to change notification settings - Fork 0
/
singtour_zco.cpp
65 lines (59 loc) · 1.64 KB
/
singtour_zco.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define MOD 1000000007
#define INF 1000000000
#define setitr set <int, greater <int> > :: iterator
typedef long long ll;
int win(pair<int, int> p1, pair<int, int> p2)
{
if((p1.f<p2.f && p1.s>=p2.s) || (p1.f<=p2.f && p1.s>p2.s))
return 1;
else if(p2.f<p1.f && p2.s>p1.s)
return 0;
else
return -1;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
//freopen("input.txt", "r", stdin);
int n,i,j,t,k;
cin >> t;
while(t--)
{
cin >> n;
vector< pair<int, int> > l, r;
int a[n] = {0};
for(i=0; i<n; i++)
{
cin >> j >> k;
l.pb(mp(j,i));
r.pb(mp(k,i));
}
sort(l.begin(), l.end());
sort(r.begin(), r.end());
for(i=0; i<n; i++)
{
a[l[i].s] += n - i - 1; //points are added for all L that are > L[i]
a[r[i].s] += i; //points added for all R < R[i]
}
/*
1 point is added for all L > L[i]
1 point added for all R < R[i]
therefore, if (L,R) wins again another (l,r), 2 points are added for L<l and R>r.
In all other draws, atleast one L or R is greater than r or l.
If its a loss, L>l and R<r so 0 points.
By this way, all necessary points are given.
This solution works as the draw points is half the win points.
*/
for(i=0; i<n; i++)
cout << a[i] << " ";
cout << "\n";
}
return 0;
}