Submission #387088

# Submission time Handle Problem Language Result Execution time Memory
387088 2021-04-07T22:39:01 Z achibasadzishvili Fish (IOI08_fish) C++17
95 / 100
655 ms 65536 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],t[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;
}
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[i] >> Y[i];
        raod[Y[i]]++;
    }
    for(int i=1; i<=k; i++){
        v[i] = vector<int>(raod[i]);
        raod[i] = 0;
    }
    for(int i=1; i<=n; i++){
        v[Y[i]][raod[Y[i]]] = X[i];
        raod[Y[i]]++;
    }
    
    vector<pair<ll,ll> >g;
    for(int i=1; i<=k; i++){
        sort(v[i].begin() , v[i].end());
        if(v[i].size()){
            g.pb(mp(v[i][v[i].size() - 1] , i));
        }
    }
    for(int i=0; i<k; i++){
        change(i);
    }
    sort(g.begin() , g.end());
    
    for(int i=0; i<g.size(); i++){
        t[i] = v[g[i].s];
    }
    ll l,r,mid,ind;
    for(int i=0; i<k; i++){
        v[i] = t[i];
        t[i].clear();
        m[i] = v[i][(int)v[i].size() - 1];
    }
    for(int i=0; i<k; i++){
        for(int j=0; j<v[i].size(); j++){
            l = 0,r = k - 1,ind = -1;
            while(r >= l){
                mid = (l + r) / 2;
                if(m[mid] >= 2 * v[i][j]){
                    r = mid - 1;
                    ind = mid;
                }
                else {
                    l = mid + 1;
                }
            }
            if(ind != -1){
                t[ind].pb(i);
            }
        }
    }
    pair<ll,ll>p;
    for(int i=0; i<k; i++){
        for(int j=0; j<t[i].size(); j++){
            in[t[i][j]]++;
            change(t[i][j]);
        }
        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:59: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]
   59 |     for(int i=0; i<g.size(); i++){
      |                  ~^~~~~~~~~
fish.cpp:69:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for(int j=0; j<v[i].size(); j++){
      |                      ~^~~~~~~~~~~~
fish.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |         for(int j=0; j<t[i].size(); j++){
      |                      ~^~~~~~~~~~~~
fish.cpp:92:39: warning: right operand of comma operator has no effect [-Wunused-value]
   92 |         l = i + 1,r = k - 1,mid,ind = k;
      |                                       ^
fish.cpp:33:8: warning: unused variable 'x' [-Wunused-variable]
   33 |     ll x,y;
      |        ^
fish.cpp:33:10: warning: unused variable 'y' [-Wunused-variable]
   33 |     ll x,y;
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23916 KB Output is correct
2 Correct 18 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23916 KB Output is correct
2 Correct 173 ms 35108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 24044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 29224 KB Output is correct
2 Correct 103 ms 29648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 24172 KB Output is correct
2 Correct 21 ms 24172 KB Output is correct
3 Correct 20 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 31156 KB Output is correct
2 Correct 222 ms 35316 KB Output is correct
3 Correct 207 ms 35052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 186 ms 35316 KB Output is correct
2 Correct 192 ms 34112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 29932 KB Output is correct
2 Correct 206 ms 35568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 34160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 221 ms 35260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 210 ms 34916 KB Output is correct
2 Correct 306 ms 38368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 499 ms 42980 KB Output is correct
2 Correct 409 ms 41564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 46432 KB Output is correct
2 Correct 419 ms 39392 KB Output is correct
3 Correct 547 ms 52376 KB Output is correct
4 Correct 433 ms 39776 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 655 ms 48604 KB Output is correct
2 Runtime error 362 ms 65536 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -