답안 #118251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
118251 2019-06-18T12:51:01 Z baluteshih Fish (IOI08_fish) C++14
70 / 100
3000 ms 39440 KB
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define MEM(i,j) memset(i,j,sizeof i)
#define F first
#define S second
#define MP make_pair
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll INF=1e9;
ll MOD;
pll fish[500005];
vector<pll> pl[500005],place;
bitset<500005> vis;
ll cnt[500005],bound[500005];
 
int main()
{jizz
	ll n,k,ans=0,tmp,num,nw;
	cin >> n >> k >> MOD,nw=n-1;
	for(int i=0;i<n;++i)
		cin >> fish[i].F >> fish[i].S,++cnt[fish[i].S];
	sort(fish,fish+n);
	for(int i=0;i<n;++i)
		pl[fish[i].S].pb(MP(fish[i].F,1));
	for(int i=1;i<=k;++i)
		place.pb(MP(pl[i].back().F,i));
	sort(ALL(place));
	for(int i=n-1;i>=0;--i)
		if(!vis[fish[i].S])
		{
			vector<pll> v;
			vis[fish[i].S]=1,tmp=1;
			while(nw>=0&&fish[nw].F*2>fish[i].F)
				--cnt[fish[nw].S],--nw;
			for(int j=0,t=0;j<k;++j)
			{
				while(t<pl[fish[i].S].size()&&pl[fish[i].S][t].F*2<=place[j].F)
					++t;
				bound[place[j].S]=t+1;
			}
			for(int j=1;j<=k;++j)
				if(!vis[j])
				{
					tmp=tmp*(cnt[j]+1)%MOD;
					if(cnt[j]==0) pl[j].back().S=pl[j].back().S*(upper_bound(ALL(pl[fish[i].S]),MP(pl[j].back().F/2,INF))-pl[fish[i].S].begin()+1)%MOD;
					else if(cnt[j]<pl[j].size())
						pl[j][cnt[j]-1].S=pl[j][cnt[j]-1].S*(upper_bound(ALL(pl[fish[i].S]),MP(pl[j].back().F/2,INF))-pl[fish[i].S].begin()+1)%MOD;
				}
			num=1,tmp=tmp*pl[fish[i].S].back().S%MOD;
			ans=(ans+tmp)%MOD;
			for(int j=0;j<pl[fish[i].S].size()&&pl[fish[i].S][j].F*2<=fish[i].F;++j)
				tmp=tmp*pl[fish[i].S][j].S%MOD,ans=(ans+tmp)%MOD;
		}
	cout << ans << "\n";
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:44:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(t<pl[fish[i].S].size()&&pl[fish[i].S][t].F*2<=place[j].F)
           ~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:53:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
      else if(cnt[j]<pl[j].size())
              ~~~~~~^~~~~~~~~~~~~
fish.cpp:58:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<pl[fish[i].S].size()&&pl[fish[i].S][j].F*2<=fish[i].F;++j)
                ~^~~~~~~~~~~~~~~~~~~~~
fish.cpp:25:19: warning: variable 'num' set but not used [-Wunused-but-set-variable]
  ll n,k,ans=0,tmp,num,nw;
                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12076 KB Output is correct
2 Correct 12 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 12160 KB Output is correct
2 Correct 175 ms 28100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 12288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 20088 KB Output is correct
2 Correct 101 ms 21364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 12408 KB Output is correct
2 Correct 36 ms 12416 KB Output is correct
3 Correct 63 ms 12388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 199 ms 24728 KB Output is correct
2 Correct 333 ms 29600 KB Output is correct
3 Correct 342 ms 30924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 210 ms 31068 KB Output is correct
2 Correct 452 ms 32520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 381 ms 24800 KB Output is correct
2 Correct 1821 ms 30940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3040 ms 30284 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3031 ms 33036 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3076 ms 27176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3021 ms 36496 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3019 ms 36452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3024 ms 39440 KB Time limit exceeded
2 Halted 0 ms 0 KB -