답안 #387096

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
387096 2021-04-07T22:48:20 Z achibasadzishvili Fish (IOI08_fish) C++17
100 / 100
1884 ms 46940 KB
#include<bits/stdc++.h>
#define ll int
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
ll ans;
ll n,k,mod,in[500005],s[1500005],pown=1,m[500005],X[500005],Y[500005],raod[500005];
vector<ll>v[500005];
void change(ll x){
    x = pown + x;
    s[x]++;
    s[x] %= mod;
    x /= 2;
    while(x){
        s[x] = s[2 * x] * s[2 * x + 1] % mod;
        x /= 2;
    }
}
ll get(ll x,ll L,ll R,ll l,ll r){
    if(L > r || R < l)return 1;
    if(L >= l && R <= r)return s[x];
    ll k1 = get(2 * x , L , (L + R) / 2 , l , r);
    ll k2 = get(2 * x + 1 , (L + R) / 2 + 1 , R , l , r);
    return k1 * k2 % mod;
}
bool cmp(vector<int>a,vector<int>b){
    return a[a.size() - 1] < b[b.size() - 1];
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n >> k >> mod;
    while(pown <= k + 2)
        pown *= 2;
    ll x,y;
    for(int i=1; i<=n; i++){
        cin >> x >> y;
        y--;
        v[y].pb(x);
    }
    for(int i=0; i<k; i++){
        sort(v[i].begin() , v[i].end());
        change(i);
    }
    sort(v , v + k , cmp);
    ll l,r,mid,ind;
    vector<pair<int,int> >q;
    for(int i=0; i<k; i++){
        m[i] = v[i][(int)v[i].size() - 1];
        for(int j=0; j<v[i].size(); j++){
            q.pb(mp(v[i][j] , i));
        }
    }
    sort(q.begin() , q.end());
    ll op = 0;
    pair<ll,ll>p;
    for(int i=0; i<k; i++){
        while(op < q.size() && q[op].f * 2 <= m[i]){
            change(q[op].s);
            in[q[op].s]++;
            op++;
        }
        l = i + 1,r = k - 1,mid,ind = k;
        while(r >= l){
            mid = (l + r) / 2;
            if(m[mid] >= 2 * v[i][in[i]]){
                r = mid - 1;
                ind = mid;
            }
            else {
                l = mid + 1;
            }
        }
        ind--;
        ans = (ans + get(1 , 1 , pown , 1 , i) * get(1 , 1 , pown , i + 2 , ind + 1)) % mod;
        ans = (ans + in[i] % mod * get(1 , 1 , pown , 1 , i)) % mod;
    }
    
    
    cout << ans << '\n';
    
    
    
    return 0;
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:51:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         for(int j=0; j<v[i].size(); j++){
      |                      ~^~~~~~~~~~~~
fish.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         while(op < q.size() && q[op].f * 2 <= m[i]){
      |               ~~~^~~~~~~~~~
fish.cpp:64:39: warning: right operand of comma operator has no effect [-Wunused-value]
   64 |         l = i + 1,r = k - 1,mid,ind = k;
      |                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12140 KB Output is correct
2 Correct 10 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 12140 KB Output is correct
2 Correct 186 ms 20064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 16368 KB Output is correct
2 Correct 114 ms 16280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 12396 KB Output is correct
2 Correct 13 ms 12396 KB Output is correct
3 Correct 14 ms 12268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 19284 KB Output is correct
2 Correct 299 ms 19740 KB Output is correct
3 Correct 286 ms 20360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 214 ms 20444 KB Output is correct
2 Correct 225 ms 20064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 19440 KB Output is correct
2 Correct 242 ms 20072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 239 ms 20320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 283 ms 20960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 308 ms 20572 KB Output is correct
2 Correct 515 ms 22876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 756 ms 24288 KB Output is correct
2 Correct 607 ms 23644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 585 ms 25436 KB Output is correct
2 Correct 611 ms 23252 KB Output is correct
3 Correct 804 ms 29380 KB Output is correct
4 Correct 586 ms 23252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 963 ms 26712 KB Output is correct
2 Correct 1738 ms 46940 KB Output is correct
3 Correct 1884 ms 45960 KB Output is correct
4 Correct 1607 ms 43224 KB Output is correct