Submission #776573

# Submission time Handle Problem Language Result Execution time Memory
776573 2023-07-08T04:13:53 Z salmon Fish (IOI08_fish) C++14
49 / 100
3000 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
int N,M;
int mod;
int l,h;
const int sq = 200;
vector<pair<int,int>> v;
long long int pown[sq + 5][500100];

int main(){
	scanf(" %d",&N);
	scanf(" %d",&M);
	
	scanf(" %d",&mod);
	
	int mep[500100];
	set<int> one;
	int mepu[500100];
	set<int> oneu;
	bool usable[M + 1];
	
	for(int i = 1; i <= M; i++){
		mep[i] = -1;
		mepu[i] = -1;
	}
	
	for(int j = 1; j <= sq + 1; j++){
		pown[j][0] = 1;
		for(int i = 1; i <= M; i++){
			pown[j][i] = pown[j][i - 1] * j % mod;
		}
	}
	
	for(int i = 0; i <= M; i++) usable[i] = false;
	
	for(int i = 0; i < N; i++){
		scanf(" %d",&l);
		scanf(" %d",&h);
		
		v.push_back(make_pair(l,h));
	}
	
	sort(v.begin(),v.end(),greater<pair<int,int>>());
	
	set<int> o;
	set<int> smol;
	vector<pair<int,int>> oh;
	
	for(int i = 0; i < v.size(); i++){
		if(o.find(v[i].second) == o.end()){
			oh.push_back(v[i]);
			o.insert(v[i].second);
		}
	}
	
	int it = 0;
	
	reverse(v.begin(),v.end());

	int bigans = 0;
	
	vector<pair<int,int>> tempuse;
	
	for(int i = 0; i < N; i++){
		while(it != N && v[i].first >= v[it].first * 2){
			if(usable[v[it].second]){
				if(one.find(v[it].second) != one.end() && mep[v[it].second] == -1){
					one.erase(v[it].second);
					mep[v[it].second] = 2;
				}
				else if(mep[v[it].second] == -1){
					one.insert(v[it].second);
				}
				else{
					mep[v[it].second]++;
				}
				
				it++;
			}
			else{
				if(oneu.find(v[it].second) != oneu.end() && mepu[v[it].second] == -1){
					oneu.erase(v[it].second);
					mepu[v[it].second] = 2;
				}
				else if(mepu[v[it].second] == -1){
					oneu.insert(v[it].second);
				}
				else{
					mepu[v[it].second]++;
				}
				
				it++;
			}
		}
		
		if(v[i] == oh.back()){
			
			if(mepu[oh.back().second] != -1){
				mep[oh.back().second] = mepu[oh.back().second];
			}
			else if(oneu.find(oh.back().second) != oneu.end()){
				one.insert(oh.back().second);
			}
			
			usable[oh.back().second] = true;
			
			long long int ans = pown[2][one.size()];
			
			for(int i = 1; i <= M; i++){
				if(mep[i] != -1){
					ans = ans * (mep[i] + 1) % mod;
				}
			}

 			bigans += ans;
 			bigans %= mod;
 			
 			oh.pop_back();
 			
 			long long int sub = 1;
 			
 			ans = 1;
			for(int j = 0; j < oh.size(); j++){
				if(oh[j].first < v[i].first * 2){
					bool flag = false;
					
					for(int k = it; k < i; k++){
						if(oh[j].first >= v[k].first * 2 && v[k].second == v[i].second) flag = true;
					}
					
					if(flag) continue;
					
					if(oneu.find(oh[j].second) != oneu.end()){
						ans *= 2;
						ans %= mod;
					}
					else if(mepu[oh[j].second] != -1){
						ans *= (1 + mepu[oh[j].second]);
						ans %= mod;
					}
				}
			}
			
			if(one.find(v[i].second) == one.end()){
				ans *= pown[2][one.size()];
				sub *= pown[2][one.size()];
			}
			else{
				ans *= pown[2][one.size() - 1];
				sub *= pown[2][one.size() - 1];
			}
			ans %= mod;
			sub %= mod;
			
			for(int j = 1; j <= M; j++){
				if(mep[j] != -1 && j != v[i].second){
					ans = ans * (mep[j] + 1) % mod;
					sub = sub * (mep[j] + 1) % mod;
				}
			}

 			ans -= sub;
			ans =(ans + mod) % mod;
			bigans += ans;
			bigans %= mod;
			
			//printf("%d %d %d %d\n",v[i].first,bigans,ans,sub);
		}
	}
	
	printf("%d",bigans);
}
/*
 * 
5
3
700
8 3
7 2
4 1
2 3
2 2
* 
 */

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:49:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
fish.cpp:123:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |    for(int j = 0; j < oh.size(); j++){
      |                   ~~^~~~~~~~~~~
fish.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  scanf(" %d",&N);
      |  ~~~~~^~~~~~~~~~
fish.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  scanf(" %d",&M);
      |  ~~~~~^~~~~~~~~~
fish.cpp:14:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  scanf(" %d",&mod);
      |  ~~~~~^~~~~~~~~~~~
fish.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |   scanf(" %d",&l);
      |   ~~~~~^~~~~~~~~~
fish.cpp:38:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |   scanf(" %d",&h);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5844 KB Output is correct
2 Correct 2 ms 5844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5844 KB Output is correct
2 Correct 173 ms 10056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1527 ms 8320 KB Output is correct
2 Correct 739 ms 8256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 922 ms 9192 KB Output is correct
2 Correct 631 ms 7516 KB Output is correct
3 Correct 668 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 12548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1746 ms 13112 KB Output is correct
2 Execution timed out 3077 ms 14332 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3029 ms 16340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3080 ms 29032 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3032 ms 39384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 64 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -