Submission #780555

# Submission time Handle Problem Language Result Execution time Memory
780555 2023-07-12T10:10:12 Z jamezzz Fish (IOI08_fish) C++17
100 / 100
455 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define dbg(...) printf(__VA_ARGS__);
#define getchar_unlocked getchar
#else
#define dbg(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb push_back
#define psf push_front
#define ppb pop_back
#define ppf pop_front
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(),x.end()
#define lb(x,v) (lower_bound(all(x),v)-x.begin())
#define ub(x,v) (upper_bound(all(x),v)-x.begin())
#define disc(x) sort(all(x));x.resize(unique(all(x))-x.begin());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> iii;
typedef tuple<int,int,int,int> iiii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
mt19937 rng(time(0));

inline int rd(){
	int x=0;
	char ch=getchar_unlocked();
	while(!(ch&16))ch=getchar_unlocked();//keep reading while current character is whitespace
    while(ch&16){//this will break when ‘\n’ or ‘ ‘ is encountered
		x=(x<<3)+(x<<1)+(ch&15);
		ch=getchar_unlocked();
	}
	return x;
}

#define maxn 500005

int n,k,mod;
vector<ii> v;

struct node{
	int s,e,m,v;
	node *l,*r;
	node(int _s,int _e){
		s=_s,e=_e,m=(s+e)>>1,v=1;
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	void add(int x){
		if(s==x&&e==x){
			v=(v+1)%mod;
			return;
		}
		if(x<=m)l->add(x);
		else r->add(x);
		v=(l->v*r->v)%mod;
	}
	int qry(int x,int y){
		if(s==x&&e==y)return v;
		if(y<=m)return l->qry(x,y);
		if(x>m)return r->qry(x,y);
		return (l->qry(x,m)*r->qry(m+1,y))%mod;
	}
}*rt;

int la[maxn],ord[maxn],num[maxn],pos[maxn],e[maxn],bad[maxn];
vi stuff;

int main(){
	sf("%d%d%d",&n,&k,&mod);
	for(int i=0;i<n;++i){
		int l,t;
		sf("%d%d",&l,&t);
		v.pb({l,t});
	}
	sort(all(v));
	rt=new node(0,k-1);
	memset(la,-1,sizeof la);
	int cnt=k-1;
	for(int i=n-1;i>=0;--i){
		auto[l,t]=v[i];
		if(la[t]==-1){
			stuff.pb(l);
			la[t]=i;
			ord[t]=cnt--;
		}
	}
	for(int i=0;i<n;++i){
		auto[l,t]=v[i];
		int ml=v[la[t]].fi;
		if(2*l<=ml)++e[t];
		pos[i]=num[t]++;
	}
	memset(bad,-1,sizeof bad);
	for(int i=0;i<n;++i){
		auto[l,t]=v[i];
		if(pos[i]==e[t])bad[t]=l;
	}
	int ptr=0;
	reverse(all(stuff));
	int ans=0;
	for(int i=0;i<n;++i){
		auto[l,t]=v[i];
		while(ptr<=i&&v[ptr].fi*2<=l){
			rt->add(ord[v[ptr].se]);
			++ptr;
		}
		if(la[t]!=i)continue;
		int r=(bad[t]==-1)?k-1:(lb(stuff,2*bad[t])-1);
		int m=ord[t]+1;//lb(stuff,l+1);
		if(0<=m-1){//partial
			int tmp=1;
			if(ord[t]!=0)tmp*=rt->qry(0,ord[t]-1);
			tmp%=mod;
			if(ord[t]!=m-1)tmp*=rt->qry(ord[t]+1,m-1);
			tmp%=mod;
			tmp*=(e[t]%mod);
			tmp%=mod;
			ans+=tmp;
			ans%=mod;
		}
		if(0<=r){//full
			int tmp=1;
			if(ord[t]!=0)tmp*=rt->qry(0,ord[t]-1);
			tmp%=mod;
			if(ord[t]!=r)tmp*=rt->qry(ord[t]+1,r);
			tmp%=mod;
			ans+=tmp;
			ans%=mod;
		}
	}
	pf("%d\n",ans);
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:82:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |  sf("%d%d%d",&n,&k,&mod);
      |    ^
fish.cpp:85:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |   sf("%d%d",&l,&t);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 3 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
2 Correct 145 ms 10140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 6684 KB Output is correct
2 Correct 72 ms 7240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4436 KB Output is correct
2 Correct 4 ms 4436 KB Output is correct
3 Correct 3 ms 4436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 7904 KB Output is correct
2 Correct 176 ms 10320 KB Output is correct
3 Correct 156 ms 17048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 142 ms 10236 KB Output is correct
2 Correct 170 ms 17360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 8076 KB Output is correct
2 Correct 162 ms 10872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 161 ms 10864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 12196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 138 ms 14672 KB Output is correct
2 Correct 163 ms 28944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 308 ms 26868 KB Output is correct
2 Correct 209 ms 29748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 26464 KB Output is correct
2 Correct 287 ms 29264 KB Output is correct
3 Correct 267 ms 38792 KB Output is correct
4 Correct 269 ms 29144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 400 ms 33036 KB Output is correct
2 Correct 421 ms 65536 KB Output is correct
3 Correct 334 ms 65536 KB Output is correct
4 Correct 455 ms 64088 KB Output is correct