제출 #265472

#제출 시각아이디문제언어결과실행 시간메모리
265472evpipisFish (IOI08_fish)C++11
80 / 100
3095 ms11384 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back typedef pair<int, int> ii; const int len = 5e5+5; int n, k, m; ii fish[len], big[len]; int fir[len], cnt[len], pos[len], mx[len]; //ii fish[len]; //int tree[4*len], vis[len], big[len]; int add(int a, int b){ return (a+b)%m; } int mul(int a, int b){ return (a*1LL*b)%m; } /*void build(int p, int l, int r){ if (l == r) return void(tree[p] = 1); int mid = (l+r)/2; build(2*p, l, mid); build(2*p+1, mid+1, r); tree[p] = mul(tree[2*p], tree[2*p+1]); } void update(int p, int l, int r, int i){ if (l == r) return void(tree[p] = add(tree[p], 1)); int mid = (l+r)/2; if (i <= mid) update(2*p, l, mid, i); else update(2*p+1, mid+1, r, i); tree[p] = mul(tree[2*p], tree[2*p+1]); } int query(int p, int l, int r, int i, int j){ if (r < i || j < l) return 1; if (i <= l && r <= j) return tree[p]; int mid = (l+r)/2; return mul(query(2*p, l, mid, i, j), query(2*p+1, mid+1, r, i, j)); } int without(int i){ return mul(query(1, 1, k, 1, i-1), query(1, 1, k, i+1, k)); } void print(int p = 1, int l = 1, int r = k){ if (l == r) return void(printf("%d ", tree[p])); int mid = (l+r)/2; print(2*p, l, mid); print(2*p+1, mid+1, r); if (p == 1) printf("\n"); }*/ struct{ set<vector<int> > mys; vector<int> comb; void gen(int i, int spec){ if (i == 0){ //printf("now I generated a combination\n"); //for (int j = 0; j < comb.size(); j++) // printf("%d ", comb[j]); //printf("\n"); return void(mys.insert(comb));} int st = 0; if (spec == i) st = 1; for (int j = st; j <= cnt[i]; j++){ comb.push_back(j); gen(i-1, spec); comb.pop_back(); } } int solve(){ for (int i = 1; i <= k; i++) cnt[i] = 0; for (int j = 0; j < n; j++) cnt[fish[j].se]++; for (int i = k-1, j = n-1; i >= 0; i--){ while (j >= 0 && big[i].fi < 2*fish[j].fi) cnt[fish[j--].se]--; int pre = mys.size(); cnt[big[i].se]++; gen(k, big[i].se); cnt[big[i].se]--; int cur = mys.size(); printf("brute: i = %d, new_combs = %d\n", i, cur-pre); } int sz = mys.size(); //printf("sz = %d\n", sz); return sz%m; } } brute; int solve(){ /// now fix big[], pos[] for (int i = 1; i <= k; i++) pos[i] = -1; for (int i = n-1, j = 0; i >= 0; i--) if (pos[fish[i].se] == -1) big[j] = fish[i], pos[fish[i].se] = j++; for (int i = 1; i <= k; i++) pos[i] = k-pos[i]-1; reverse(big, big+k); /// fix fir[] for (int i = 1; i <= k; i++) cnt[i] = 0, mx[i] = -1; for (int i = 0; i < k; i++) fir[i] = k; for (int i = 0, j = 0; i < k; i++){ while (big[i].fi >= 2*fish[j].fi){ cnt[fish[j].se]++; if (cnt[fish[j].se] == mx[fish[j].se]) fir[pos[fish[j].se]] = i; j++; } mx[big[i].se] = cnt[big[i].se]+1; } //for (int i = 0; i < k; i++) // printf("fir%d: %d\n", i, fir[i]); /// compute the answer for (int i = 1; i <= k; i++) cnt[i] = 0; //for (int i = 0; i < k; i++) // printf("big%d: (%d, %d)\n", i, big[i].fi, big[i].se); int ans = 0; for (int i = 0, j = 0; i < k; i++){ while (big[i].fi >= 2*fish[j].fi) cnt[fish[j++].se]++; //printf("i = %d, f = (%d, %d), fir = %d\n", i, big[i].fi, big[i].se, fir[i]); int full = 1, par = 1; for (int f = 0; f < k; f++){ int c = cnt[big[f].se]; if (f < i) full = mul(full, c+1), par = mul(par, c+1); else if (f == i) par = mul(par, c); else if (f < fir[i]) full = mul(full, c+1); } //printf("ins solve: i = %d, new_combs = %d\n", i, full+par); //printf("length = %d, type = %d, par = %d, full = %d\n", big[i].fi, big[i].se, par, full); ans = add(ans, add(full, par)); } return ans; } int main(){ //freopen("fish.txt", "r", stdin); /// read input and sort fish[] scanf("%d %d %d", &n, &k, &m); for (int i = 0; i < n; i++) scanf("%d %d", &fish[i].fi, &fish[i].se); sort(fish, fish+n); //for (int i = 0; i < n; i++) // printf("fish%d: (%d, %d)\n", i, fish[i].fi, fish[i].se); printf("%d\n", solve()); //printf("brute: %d\n", brute.solve()); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

fish.cpp: In function 'int main()':
fish.cpp:196:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  196 |     scanf("%d %d %d", &n, &k, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:198:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  198 |         scanf("%d %d", &fish[i].fi, &fish[i].se);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...