답안 #777678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777678 2023-07-09T12:56:55 Z salmon Fish (IOI08_fish) C++14
100 / 100
593 ms 65532 KB
#include <bits/stdc++.h>
using namespace std;
int N,M;
int mod;
int l,h;
vector<pair<int,int>> v;
vector<pair<int,int>> oh;
int mapping[500100];
bool o[500100];
int iv[500100];

struct node{
	int s,e;
	long long int v;
	node *l,*r;

	node(int S, int E){
		s = S;
		e = E;
		int m = (s + e)/2;

		v = 1;

		if(s != e){
			l = new node(s,m);
			r = new node(m + 1, e);
		}
	}

	void update(int i, int k){
		if(s == e){
			v += k;
			v %= mod;
			return;
		}

		int m = (s + e)/2;

		if(i <= m){
			l -> update(i,k);
		}
		else{
			r -> update(i,k);
		}

		v = (l -> v * r -> v) % mod;
	}

	long long int query(int S, int E){
		if(E < S) return 1;

		if(S <= s && e <= E){
			return v;
		}

		int m = (s + e)/2;

		long long int V = 1;

		if(S <= m){
			V *= l -> query(S,E);
		}
		if(m < E){
			V *= r -> query(S,E);
		}

		return V % mod;
	}

}*lroot;



int main(){
	scanf(" %d",&N);
	scanf(" %d",&M);

	scanf(" %d",&mod);

	int next[500100];

	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>>());

	for(int i = 0; i <= M; i++){
		o[i] = true;
	}

	for(int i = 0; i < v.size(); i++){
		if(o[v[i].second]){
			oh.push_back(v[i]);
			o[v[i].second] = false;
			iv[v[i].second] = v.size() - 1 - i;
		}
		if(v[i].first * 2 > v[v.size() - 1 - iv[v[i].second]].first ){
			next[v[i].second] = v[i].first;
		}
	}

	lroot = new node(0,M);

	int it = 0;
	int it1 = 0;

	reverse(oh.begin(),oh.end());

	for(int i = 0; i < oh.size(); i++){
		mapping[oh[i].second] = i;
	}

	reverse(oh.begin(),oh.end());

	reverse(v.begin(),v.end());

	long long int bigans = 0;

	M = oh.size();

	for(int i = 0; i < N; i++){
		while(it != N && v[i].first >= v[it].first * 2){
			lroot -> update(mapping[v[it].second], 1);
            it++;
        }

		if(i == iv[oh.back().second]){
 			bigans += lroot -> query(0,M - oh.size());
 			bigans %= mod;

            int e = lower_bound(oh.begin(),oh.end(),make_pair(next[v[i].second] * 2 - 1, 1100100100),greater<pair<int,int>>()) -> second;

            bigans += (lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[e] ) - 1 + mod);
			bigans %= mod;

			oh.pop_back();
		}
	}

	printf("%d",bigans);
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:95: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]
   95 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
fish.cpp:113: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]
  113 |  for(int i = 0; i < oh.size(); i++){
      |                 ~~^~~~~~~~~~~
fish.cpp:144:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  144 |  printf("%d",bigans);
      |          ~^  ~~~~~~
      |           |  |
      |           |  long long int
      |           int
      |          %lld
fish.cpp:109:6: warning: unused variable 'it1' [-Wunused-variable]
  109 |  int it1 = 0;
      |      ^~~
fish.cpp:75:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |  scanf(" %d",&N);
      |  ~~~~~^~~~~~~~~~
fish.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf(" %d",&M);
      |  ~~~~~^~~~~~~~~~
fish.cpp:78:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |  scanf(" %d",&mod);
      |  ~~~~~^~~~~~~~~~~~
fish.cpp:83:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |   scanf(" %d",&l);
      |   ~~~~~^~~~~~~~~~
fish.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |   scanf(" %d",&h);
      |   ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 1 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2260 KB Output is correct
2 Correct 148 ms 6476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 4404 KB Output is correct
2 Correct 83 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2516 KB Output is correct
2 Correct 3 ms 2388 KB Output is correct
3 Correct 4 ms 2560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 6460 KB Output is correct
2 Correct 185 ms 6388 KB Output is correct
3 Correct 170 ms 6436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 6472 KB Output is correct
2 Correct 170 ms 6496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 92 ms 6476 KB Output is correct
2 Correct 182 ms 6980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 7056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 224 ms 8224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 10892 KB Output is correct
2 Correct 200 ms 17176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 344 ms 22384 KB Output is correct
2 Correct 261 ms 21180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 22316 KB Output is correct
2 Correct 304 ms 17172 KB Output is correct
3 Correct 341 ms 28304 KB Output is correct
4 Correct 336 ms 17252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 448 ms 28304 KB Output is correct
2 Correct 593 ms 64700 KB Output is correct
3 Correct 501 ms 65532 KB Output is correct
4 Correct 591 ms 50412 KB Output is correct