# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
992647 |
2024-06-04T23:35:26 Z |
PedroBigMan |
Fish (IOI08_fish) |
C++14 |
|
393 ms |
65536 KB |
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <list>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
#include <cstring>
using namespace std;
typedef int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define REP(i,a,b) for(ll i=(ll) a; i<(ll) b; i++)
#define pb push_back
#define mp make_pair
#define pl pair<ll,ll>
#define ff first
#define ss second
#define whole(x) x.begin(),x.end()
#define DEBUG(i) cout<<"Pedro "<<i<<endl
#define INF 1000000000000000000LL
#define EPS ((ld)0.00000000001)
#define pi ((ld)3.141592653589793)
#define VV(vvvv,NNNN,xxxx); REP(iiiii,0,NNNN) {vvvv.pb(xxxx);}
ll mod=1000000007;
template<class A=ll>
void Out(vector<A> a) {REP(i,0,a.size()) {cout<<a[i]<<" ";} cout<<endl;}
template<class A=ll>
void In(vector<A> &a, ll N) {A cur; REP(i,0,N) {cin>>cur; a.pb(cur);}}
ll NN; ll x,y, thisans;
vector<ll> pp;
vector<pl> range;
void ST(vector<ll> arr)
{
NN= (ll) 1<<(ll) ceil(log2(arr.size()));
REP(i,0,2*NN) {range.pb(mp(0,0));}
REP(i,0,NN) {pp.pb(1);}
REP(i,0,arr.size()) {pp.pb(arr[i]); range[i+NN]=mp(i,i);}
REP(i,arr.size(),NN) {pp.pb(1); range[i+NN]=mp(i,i);}
ll cur = NN-1;
while(cur>0)
{
pp[cur]=(pp[2*cur]*pp[2*cur+1])%mod;
range[cur]=mp(range[2*cur].ff,range[2*cur+1].ss);
cur--;
}
}
ll query(ll a,ll b, ll c=1LL) //range [a,b], current node. initially: query(a,b)
{
if(a>b) {return 1;}
x=range[c].ff; y=range[c].ss;
if(y<a || x>b) {return 1;}
if(x>=a && y<=b) {return pp[c];}
thisans = (query(a,b,2*c)*query(a,b,2*c+1))%mod;
return thisans;
}
void update(ll s, ll a, ll b, ll c=1LL) //update LV, range [a,b], current node, current range. initially: update(s,a,b)
{
if(a>b) {return;}
x=range[c].ff; y=range[c].ss;
if(y<a || x>b) {return ;}
if(x>=a && y<=b)
{
pp[c]+=s; pp[c]%=mod;
return;
}
update(s,a,b,2*c); update(s,a,b,2*c+1);
pp[c]=(pp[2*c]*pp[2*c+1])%mod;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cout.precision(20);
ll N, K, M; cin>>N>>K>>M; mod=M;
vector<pl> p(N,{-1,-1});
REP(i,0,N) {cin>>p[i].ff>>p[i].ss; p[i].ss--;}
sort(whole(p));
vector<pl> to_order(K,{-1,-1}); REP(i,0,K) {to_order[i].ss=i;}
REP(i,0,N) {to_order[p[i].ss].ff=p[i].ff;}
sort(whole(to_order));
vector<ll> limit(K,-1), m(K,-1);
REP(i,0,K) {m[to_order[i].ss]=i; limit[i]=to_order[i].ff/2;}
vector<ll> L(N,-1); REP(i,0,N) {L[i]=p[i].ff;} REP(i,0,K) {limit[i]=(ll) (upper_bound(whole(L),limit[i])-L.begin())-1;}
REP(i,0,N) {p[i].ss=m[p[i].ss];}
vector<ll> gem(N,-1); REP(i,0,N) {gem[i]=p[i].ss;}
vector<vector<ll> > pos(K,vector<ll>()); REP(i,0,N) {pos[gem[i]].pb(i);}
vector<ll> nxt(K,-1);
REP(i,0,K) {nxt[i]=*upper_bound(whole(pos[i]),limit[i]);}
vector<ll> xx(K,1);
ST(xx);
ll gem_ind = 0; ll ans = 0; ll ind=0; ll thisgem;
while(gem_ind<K && limit[gem_ind]==-1) {gem_ind++; ans++; ans%=mod;}
ll G; ll B; vector<ll> oc(K,0);
while(ind<N && gem_ind<K)
{
thisgem = gem[ind]; update(1,thisgem,thisgem); oc[thisgem]++;
while(gem_ind<K && limit[gem_ind]==ind)
{
G=gem_ind;
B = (ll) (lower_bound(whole(limit),nxt[G]) - limit.begin()) -1;
ans+=query(0,G-1)*(query(G+1,B)+oc[G]%mod); ans%=mod;
gem_ind++;
}
ind++;
}
if(ans<0LL) {ans+=mod;} cout<<ans<<endl;
return 0;
}
Compilation message
fish.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization ("O3")
|
fish.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization ("unroll-loops")
|
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
105 ms |
10776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
4872 KB |
Output is correct |
2 |
Correct |
65 ms |
5708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Correct |
2 ms |
600 KB |
Output is correct |
3 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
82 ms |
7248 KB |
Output is correct |
2 |
Correct |
148 ms |
10800 KB |
Output is correct |
3 |
Correct |
139 ms |
10996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
141 ms |
11092 KB |
Output is correct |
2 |
Correct |
146 ms |
11540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
79 ms |
7400 KB |
Output is correct |
2 |
Correct |
147 ms |
11588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
11476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
177 ms |
13440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
13508 KB |
Output is correct |
2 |
Correct |
132 ms |
22208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
297 ms |
28412 KB |
Output is correct |
2 |
Correct |
229 ms |
25792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
277 ms |
29424 KB |
Output is correct |
2 |
Correct |
277 ms |
22132 KB |
Output is correct |
3 |
Correct |
331 ms |
34128 KB |
Output is correct |
4 |
Correct |
279 ms |
22208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
393 ms |
32964 KB |
Output is correct |
2 |
Runtime error |
174 ms |
65536 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |