Task: | Lounge Lizards |
Sender: | Hannes Ihalainen |
Submission time: | 2017-10-31 17:59:29 +0200 |
Language: | C++ |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.03 s | details |
#2 | ACCEPTED | 0.04 s | details |
#3 | ACCEPTED | 0.05 s | details |
#4 | ACCEPTED | 0.05 s | details |
#5 | ACCEPTED | 0.05 s | details |
#6 | ACCEPTED | 0.27 s | details |
#7 | ACCEPTED | 0.95 s | details |
#8 | ACCEPTED | 1.87 s | details |
#9 | ACCEPTED | 1.25 s | details |
#10 | ACCEPTED | 1.21 s | details |
Compiler report
input/code.cpp: In function 'll lis(std::vector<std::pair<long long int, long long int> >)': input/code.cpp:28:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i < v.size(); ++i) { ^ input/code.cpp:32:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for(int i = 0; i < v.size(); ++i) { ^
Code
#include <bits/stdc++.h> #define F first #define S second using namespace std; typedef long long ll; const int N = 1<<20; ll st[2*N]; ll getMax(ll a, ll b) { ll ma = 0; a += N; b += N; for(; a <= b; a/=2, b/=2) { if(a&1) ma = max(ma, st[a++]); if(~b&1) ma = max(ma, st[b--]); } return ma; } void setValue(ll a, ll v) { a += N; st[a] = v; for(a/=2; a; a/=2) { st[a] = max(st[a*2], st[a*2+1]); } } ll lis(vector<pair<ll, ll> > v) { for(int i = 0; i < v.size(); ++i) { setValue(v[i].S, max(getMax(0ll, v[i].S-1)+1, getMax(v[i].S, v[i].S))); } ll ans = getMax(0, N-1); for(int i = 0; i < v.size(); ++i) { setValue(v[i].S, 0); } return ans; } int main() { ll tx, ty; cin>>tx>>ty; int n; cin>>n; vector<pair<pair<ll, ll>, pair<ll, ll> > > v(n); for(int i = 0; i < n; ++i) { cin>>v[i].F.F>>v[i].F.S>>v[i].S.S; v[i].F.F -= tx; v[i].F.S -= ty; ll q = __gcd(abs(v[i].F.F), abs(v[i].F.S)); v[i].F.F /= q; v[i].F.S /= q; v[i].S.F = q; } sort(v.begin(), v.end()); ll ans = 0; while(v.size()) { vector<pair<ll, ll> > v2; pair<ll, ll> q = v.back().F; while(v.size() && v.back().F == q) { v2.push_back(v.back().S); v.pop_back(); } sort(v2.begin(), v2.end()); ans += lis(v2); } cout<<ans<<'\n'; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
-343683 -308818 20 -356524 -308059 6536 -345748 -315675 161545 -383273 -328712 108670 ... |
correct output |
---|
20 |
user output |
---|
20 |
Test 2
Verdict: ACCEPTED
input |
---|
-125659 230957 48 -125675 230970 48444 -125668 230973 91087 -125677 230938 272157 ... |
correct output |
---|
46 |
user output |
---|
46 |
Test 3
Verdict: ACCEPTED
input |
---|
-231847 -337029 198 -231878 -337017 148388 -231842 -337027 293504 -231882 -337050 281592 ... |
correct output |
---|
194 |
user output |
---|
194 |
Test 4
Verdict: ACCEPTED
input |
---|
174276 -51958 957 174250 -51957 150697 174292 -52000 249717 174294 -51913 116182 ... |
correct output |
---|
888 |
user output |
---|
888 |
Test 5
Verdict: ACCEPTED
input |
---|
-360562 174072 1000 -320659 143286 83633 -383543 176207 92944 -326186 200852 263889 ... |
correct output |
---|
1000 |
user output |
---|
1000 |
Test 6
Verdict: ACCEPTED
input |
---|
144204 -295812 96669 144366 -295909 23772 144029 -295537 49417 144343 -295812 260639 ... |
correct output |
---|
91745 |
user output |
---|
91745 |
Test 7
Verdict: ACCEPTED
input |
---|
137563 -36042 454046 137883 -36395 30825 137286 -36382 289604 137861 -36607 178770 ... |
correct output |
---|
411558 |
user output |
---|
411558 |
Test 8
Verdict: ACCEPTED
input |
---|
-1000000 1000000 1000000 -501195 2390 255098 -503473 6946 118923 -536505 73010 118259 ... |
correct output |
---|
1981 |
user output |
---|
1981 |
Test 9
Verdict: ACCEPTED
input |
---|
201029 -59913 632970 200955 -59635 219492 200745 -60234 117972 201214 -60208 44343 ... |
correct output |
---|
515012 |
user output |
---|
515012 |
Test 10
Verdict: ACCEPTED
input |
---|
-297020 81643 632611 -296727 81333 148497 -296527 81805 128956 -296675 81983 202069 ... |
correct output |
---|
515222 |
user output |
---|
515222 |