Submission #297160

# Submission time Handle Problem Language Result Execution time Memory
297160 2020-09-11T10:09:59 Z Kastanda Tropical Garden (IOI11_garden) C++11
100 / 100
206 ms 45984 KB
/*
    Take me to church
    I'll worship like a dog at the shrine of your lies
    I'll tell you my sins and you can sharpen your knife
    Offer me that deathless death
    Good God, let me give you my life
*/
#include<bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define x first
#define y second
using namespace std;
const int N = 150004, MXQ = 2002;
int n, m, q, p, MN[N], Q[MXQ], RS[MXQ];
int F[N * 2], D[N * 2], qu[N * 2];
vector < pair < int , int > > vec[N * 2], Adj[N];
vector < int > ps[N * 2], Adt[N * 2];
map < int , int > MP;
inline void Solve(int dt)
{
    int l = 0, r = 0;
    memset(D, -1, sizeof(D));
    for (int u : Adt[dt])
        D[u] = 1, qu[r ++] = u;
    while (r - l)
    {
        int v = qu[l ++];
        for (int u : Adt[v])
            if (D[u] == -1)
                D[u] = D[v] + 1, qu[r ++] = u;
    }
    if (D[dt] == -1)
    {
        for (int i = 0; i < n; i ++)
            if (D[i << 1] != -1)
                MP[D[i << 1]] ++;
        return ;
    }
    for (int i = 0; i < q; i ++)
        vec[Q[i] % D[dt]].push_back({Q[i], i});
    for (int i = 0; i < D[dt]; i ++)
        sort(vec[i].begin(), vec[i].end()), ps[i].resize(vec[i].size());
    for (int i = 0; i < n; i ++)
    {
        if (D[i << 1] == -1)
            continue;
        int d = D[i << 1], r = d % D[dt];
        int lb = lower_bound(vec[r].begin(), vec[r].end(), pair < int , int > {d, -1}) - vec[r].begin();
        if (lb < vec[r].size())
            ps[r][lb] ++;
    }
    for (int i = 0; i < D[dt]; i ++)
    {
        for (int j = 0; j < (int)ps[i].size() - 1; j ++)
            ps[i][j + 1] += ps[i][j];
        for (int j = 0; j < (int)vec[i].size(); j ++)
            RS[vec[i][j].second] += ps[i][j];
        vec[i].clear();
        ps[i].clear();
    }
    return ;
}
void count_routes(int _n, int _m, int _p, int _E[N][2], int _q, int _Q[MXQ])
//int main()
{
    n = _n; m = _m; p = _p; q = _q;
    //cin >> n >> m >> p >> q;
    for (int i = 0; i < q; i ++)
        Q[i] = _Q[i];
        //cin >> Q[i];
    memset(MN, 63, sizeof(MN));
    for (int i = 0; i < m; i ++)
    {
        int v = _E[i][0], u = _E[i][1];
        //int v, u;
        //cin >> v >> u;
        Adj[v].push_back({i, u});
        Adj[u].push_back({i, v});
        MN[v] = min(MN[v], i);
        MN[u] = min(MN[u], i);
    }
    for (int i = 0; i < n; i ++)
    {
        F[i << 1] = F[i << 1 | 1] = -1;
        sort(Adj[i].begin(), Adj[i].end());
        if (Adj[i].size() == 0)
            continue;
        int u = Adj[i][0].y;
        if (MN[u] < Adj[i][0].x || Adj[u].size() == 1)
            F[i << 1] = u << 1;
        else
            F[i << 1] = u << 1 | 1;
        if (Adj[i].size() == 1)
            continue;
        u = Adj[i][1].y;
        if (MN[u] < Adj[i][1].x || Adj[u].size() == 1)
            F[i << 1 | 1] = u << 1;
        else
            F[i << 1 | 1] = u << 1 | 1;
    }
    for (int i = 0; i < n + n; i ++)
        if (F[i] != -1)
            Adt[F[i]].push_back(i);

    /*for (int i = 0; i < n + n; i ++)
        printf("%d ", F[i]);
    printf("\n");*/

    Solve(p << 1);
    Solve(p << 1 | 1);
    for (int i = 0; i < q; i ++)
    {
        RS[i] += MP[Q[i]];
        answer(RS[i]);
        //printf("%d ", RS[i]);
    }
    return ;
    //return 0;
}

Compilation message

garden.cpp: In function 'void Solve(int)':
garden.cpp:50:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if (lb < vec[r].size())
      |             ~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 26880 KB Output is correct
2 Correct 19 ms 26880 KB Output is correct
3 Correct 20 ms 26880 KB Output is correct
4 Correct 19 ms 26752 KB Output is correct
5 Correct 18 ms 26752 KB Output is correct
6 Correct 19 ms 26880 KB Output is correct
7 Correct 19 ms 26752 KB Output is correct
8 Correct 19 ms 27008 KB Output is correct
9 Correct 21 ms 27136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 26880 KB Output is correct
2 Correct 19 ms 26880 KB Output is correct
3 Correct 20 ms 26880 KB Output is correct
4 Correct 19 ms 26752 KB Output is correct
5 Correct 18 ms 26752 KB Output is correct
6 Correct 19 ms 26880 KB Output is correct
7 Correct 19 ms 26752 KB Output is correct
8 Correct 19 ms 27008 KB Output is correct
9 Correct 21 ms 27136 KB Output is correct
10 Correct 21 ms 26752 KB Output is correct
11 Correct 31 ms 29160 KB Output is correct
12 Correct 49 ms 31096 KB Output is correct
13 Correct 70 ms 37752 KB Output is correct
14 Correct 151 ms 40312 KB Output is correct
15 Correct 166 ms 41336 KB Output is correct
16 Correct 147 ms 38264 KB Output is correct
17 Correct 141 ms 37496 KB Output is correct
18 Correct 50 ms 31096 KB Output is correct
19 Correct 160 ms 40316 KB Output is correct
20 Correct 187 ms 41408 KB Output is correct
21 Correct 144 ms 38264 KB Output is correct
22 Correct 136 ms 37240 KB Output is correct
23 Correct 158 ms 41336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 26880 KB Output is correct
2 Correct 19 ms 26880 KB Output is correct
3 Correct 20 ms 26880 KB Output is correct
4 Correct 19 ms 26752 KB Output is correct
5 Correct 18 ms 26752 KB Output is correct
6 Correct 19 ms 26880 KB Output is correct
7 Correct 19 ms 26752 KB Output is correct
8 Correct 19 ms 27008 KB Output is correct
9 Correct 21 ms 27136 KB Output is correct
10 Correct 21 ms 26752 KB Output is correct
11 Correct 31 ms 29160 KB Output is correct
12 Correct 49 ms 31096 KB Output is correct
13 Correct 70 ms 37752 KB Output is correct
14 Correct 151 ms 40312 KB Output is correct
15 Correct 166 ms 41336 KB Output is correct
16 Correct 147 ms 38264 KB Output is correct
17 Correct 141 ms 37496 KB Output is correct
18 Correct 50 ms 31096 KB Output is correct
19 Correct 160 ms 40316 KB Output is correct
20 Correct 187 ms 41408 KB Output is correct
21 Correct 144 ms 38264 KB Output is correct
22 Correct 136 ms 37240 KB Output is correct
23 Correct 158 ms 41336 KB Output is correct
24 Correct 22 ms 26880 KB Output is correct
25 Correct 32 ms 29312 KB Output is correct
26 Correct 56 ms 31216 KB Output is correct
27 Correct 73 ms 38008 KB Output is correct
28 Correct 151 ms 40440 KB Output is correct
29 Correct 170 ms 41716 KB Output is correct
30 Correct 144 ms 38520 KB Output is correct
31 Correct 135 ms 37624 KB Output is correct
32 Correct 52 ms 31228 KB Output is correct
33 Correct 165 ms 40440 KB Output is correct
34 Correct 206 ms 41464 KB Output is correct
35 Correct 151 ms 38496 KB Output is correct
36 Correct 152 ms 37576 KB Output is correct
37 Correct 163 ms 41592 KB Output is correct
38 Correct 156 ms 45984 KB Output is correct