Submission #677790

# Submission time Handle Problem Language Result Execution time Memory
677790 2023-01-04T11:19:55 Z vjudge1 Fish (IOI08_fish) C++14
0 / 100
461 ms 12440 KB
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;

#define ii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vii vector<ii>
#define vll vector<ll>
#define vpll vector<pll>
#define matrix vector<vi>
#define matrixLL vector<vll>
#define vs vector<string>
#define vui vector<ui>
#define msi multiset<int>
#define mss multiset<string>
#define si set<int>
#define ss set<string>
#define PB push_back
#define PF push_front
#define PPB pop_back
#define PPF pop_front
#define X first
#define Y second
#define MP make_pair
#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()

const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int dxx[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dyy[] = {0, 0, -1, 1, -1, 1, -1, 1};
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ld pi = 3.14159265;
int mod = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 7;
const int inf = mod;
const ll INF = 1e18;
const ll zero = ll(0);
const int logo = 20;
const int off = 1 << logo;
const int trsz = off << 1;

int seg[trsz];
	
void update(int x, int lo, int hi, int a, int b, int val){
	if(lo >= b or hi <= a) return;
	if(lo >= a and hi <= b){
		seg[x] = val;
		return;
	}		
	int mid = (lo + hi) / 2;
	update(x * 2, lo, mid, a, b, val);
	update(x * 2 + 1, mid, hi, a, b, val);
	seg[x] = seg[x * 2] + seg[x * 2 + 1];
	seg[x] %= mod;
}

int query(int x, int lo, int hi, int a, int b){
	if(lo >= b or hi <= a) return 0;
	if(lo >= a and hi <= b) return seg[x];
	int mid = (lo + hi) / 2;
	return (query(x * 2, lo, mid, a, b) + query(x * 2 + 1, mid, hi, a, b)) % mod;
}

vii arr;
int dp[MAXN];
int lst[MAXN];


void solve(){
	int n, k;
	cin >> n >> k >> mod;
	arr.resize(n);
	REP(i, k + 1) lst[i] = -1;
	REP(i, n) cin >> arr[i].X >> arr[i].Y;
	sort(all(arr));
	
	//cout << "SORTIRANO\n";
	//REP(i, n) cout << arr[i].X << " " << arr[i].Y << "\n";
	
	int i = 0;
	for(auto &x : arr){
		dp[i] = 1;
		if(lst[x.Y] != -1) update(1, 0, off, lst[x.Y], lst[x.Y] + 1, 0);
		else dp[i]++;
		
		int pi = upper_bound(all(arr), MP(x.X / 2, inf)) - arr.begin();
		if(pi >= 0) dp[i] = (dp[i] + query(1, 0, off, 0, pi)) % mod;
		//cout << dp[i] << " ";
		update(1, 0, off, i, i + 1, dp[i]);
		lst[x.Y] = i++;
	}
	
	//cout << "\n";
	
	int ans = 0;
	REP(i, n) ans = (ans + dp[i]) % mod;//, cout << dp[i] << " ";
	cout << ans << "\n";
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	//cin >> t;
	while(t--)solve();
	return 0;
}






# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 171 ms 5880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 272 ms 7816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 428 ms 11660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 264 ms 7884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 426 ms 10684 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 461 ms 11652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 332 ms 9824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 382 ms 11276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 11340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 428 ms 12440 KB Output isn't correct
2 Halted 0 ms 0 KB -