QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#410559#6222. 精准预测Max_s_xaM30 1989ms500616kbC++175.4kb2024-05-14 09:30:302024-05-14 09:30:30

Judging History

你现在查看的是最新测评结果

  • [2024-05-14 09:30:30]
  • 评测
  • 测评结果:30
  • 用时:1989ms
  • 内存:500616kb
  • [2024-05-14 09:30:30]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <queue>
#include <bitset>

typedef long long ll;
typedef double lf;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 5e4 + 10, MAXM = 1e5 + 10, MAXV = 5e5 + 10;

int t, n, m, ans[MAXN];

struct Edge
{
    int op, x, u, v;
}e[MAXM];
vector <int> pt[MAXN], vid[MAXN];

vector <int> g[MAXV];
int tp[MAXV], vt, bel[MAXV];

int dfn[MAXV], low[MAXV], clk, scc[MAXV], num;
int st[MAXV], top; bool inq[MAXV];
void Tarjan(int u)
{
    dfn[u] = low[u] = ++clk, st[++top] = u, inq[u] = 1;
    for (auto v : g[u])
    {
        if (!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
        else if (inq[v]) low[u] = min(low[u], dfn[v]);
    }
    if (dfn[u] == low[u])
    {
        ++num;
        while (st[top] != u) scc[st[top]] = num, inq[st[top]] = 0, top--;
        scc[u] = num, inq[u] = 0, top--;
    }
}

vector <int> tr[MAXV];
int vise[MAXV];


const int MAXB = 5002, B = 5000;
bitset <MAXB> to[2][MAXV];

int main()
{
    // freopen("A.in", "r", stdin);
    // freopen("A.out", "w", stdout);
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(t), Read(n), Read(m);
    for (int i = 1; i <= m; i++)
    {
        Read(e[i].op), Read(e[i].x), Read(e[i].u), Read(e[i].v);
        pt[e[i].u].push_back(e[i].x), pt[e[i].v].push_back(e[i].x + (e[i].op ^ 1));
    }
    for (int i = 1; i <= n; i++)
    {
        pt[i].push_back(t + 1);
        sort(pt[i].begin(), pt[i].end());
        int sz = unique(pt[i].begin(), pt[i].end()) - pt[i].begin();
        pt[i].resize(sz), vid[i].resize(sz);
        // cout << i << ' ' << sz << '\n';
        // for (auto x : pt[i]) cout << x << ' '; cout << '\n';
        int pre = 0;
        for (int j = 0; j < sz; j++)
        {
            vid[i][j] = ++vt, vt++;
            bel[vt - 1] = bel[vt] = i;
            if (pre) g[vt - 1].push_back(pre), g[pre + 1].push_back(vt);
            pre = vt - 1;
        }
        tp[vt - 1] = 1, tp[vt] = 2;
        // for (auto x : vid[i]) cout << x << ' '; cout << '\n';
    }
    for (int i = 1; i <= m; i++)
    {
        int l = lower_bound(pt[e[i].u].begin(), pt[e[i].u].end(), e[i].x) - pt[e[i].u].begin();
        int r = lower_bound(pt[e[i].v].begin(), pt[e[i].v].end(), e[i].x + (e[i].op ^ 1)) - pt[e[i].v].begin();
        l = vid[e[i].u][l], r = vid[e[i].v][r];
        // cout << l << ' ' << r << "\n";
        if (e[i].op) g[l].push_back(r + 1), g[r].push_back(l + 1);
        else g[l + 1].push_back(r + 1), g[r].push_back(l);
    }
    for (int i = 1; i <= vt; i++)
        if (!dfn[i]) Tarjan(i);
    // for (int i = 1; i <= vt; i++) cout << scc[i] << ' '; cout << '\n';
    for (int i = 1; i <= vt; i++)
    {
        for (auto v : g[i])
            if (scc[i] != scc[v] && vise[scc[v]] != i) tr[scc[i]].push_back(scc[v]), vise[scc[v]] = i;
    }
    for (int d = 1; d <= (n - 1) / B + 1; d++)
    {
        int l = (d - 1) * B + 1, r = min(n, d * B);
        for (int i = 1; i <= num; i++) to[0][i].reset(), to[1][i].reset();
        for (int i = l; i <= r; i++) to[0][scc[vid[i].back()]].set(i - l), to[1][scc[vid[i].back() + 1]].set(i - l);
        for (int i = 1; i <= num; i++)
        {
            for (auto v : tr[i])
                to[0][i] |= to[0][v], to[1][i] |= to[1][v];
        }
        for (int i = 1; i <= n; i++)
        {
            if (ans[i] == -1) continue;
            int u = scc[vid[i].back()];
            if ((to[0][u] & to[1][u]).count()) ans[i] = -1;
            else ans[i] += to[1][u].count();
        }
    }
    for (int i = 1; i <= n; i++)
        if (ans[i] == -1) cout << "0\n";
        else cout << n - 1 - ans[i] << ' ';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 40368kb

input:

2 10 10
0 1 5 3
0 1 10 10
1 1 4 4
1 1 10 3
0 1 2 5
1 1 8 1
1 1 10 8
0 1 2 2
1 2 10 3
1 2 8 3

output:

8 9 7 0
9 9 9 6 9 7 

result:

wrong answer 1st numbers differ - expected: '7', found: '8'

Test #2:

score: 0
Wrong Answer
time: 7ms
memory: 41296kb

input:

100 100 200
1 98 31 73
0 75 20 71
1 61 95 74
1 33 42 5
0 70 67 67
1 46 27 80
1 80 70 62
0 34 25 97
1 58 7 43
1 23 26 10
0 8 86 59
0 85 51 41
1 8 54 72
0 7 59 29
0 8 31 9
0 92 88 3
0 34 31 50
1 63 85 90
0 85 66 69
0 32 45 71
1 47 21 21
0 58 2 16
0 14 17 84
1 32 12 10
0 11 40 31
0 70 85 67
0 36 35 84
...

output:

98 93 85 93 93 98 96 85 97 88 97 0
96 98 0
92 92 99 99 93 0
98 96 93 98 96 89 0
93 93 96 91 97 96 94 96 92 96 95 95 94 94 87 97 98 87 0
98 83 0
98 88 96 97 99 94 95 95 96 87 92 98 93 98 96 90 0
96 91 92 93 86 87 90 94 88 96 99 85 92 94 97 95 88 85 98 0
96 98 94 95 98 95 99 93 98 94 88 80 98 

result:

wrong answer 1st numbers differ - expected: '90', found: '98'

Test #3:

score: 10
Accepted
time: 3ms
memory: 39616kb

input:

100 100 200
0 18 72 87
0 26 100 8
1 2 84 58
1 90 92 65
0 31 23 62
1 69 70 52
1 87 74 45
0 71 1 17
1 2 64 54
1 51 43 62
0 3 17 44
1 18 41 27
0 21 67 30
1 67 76 22
0 66 76 59
1 53 49 78
0 96 47 49
1 52 78 95
0 59 73 60
1 20 64 40
0 39 20 70
0 46 63 69
0 62 8 14
0 6 33 47
1 52 39 45
1 11 70 30
0 86 26 ...

output:

91 88 98 99 92 94 98 96 96 98 96 98 97 95 96 95 85 97 89 98 95 97 92 99 96 93 93 94 98 94 98 93 91 98 96 91 99 89 89 86 89 96 92 96 93 94 85 95 82 91 96 98 90 93 96 97 91 90 94 92 91 95 95 89 96 93 99 98 99 87 98 94 95 96 93 97 96 95 93 88 90 94 99 86 95 91 97 92 87 96 85 94 99 98 92 93 96 95 99 92 

result:

ok 100 numbers

Test #4:

score: 0
Wrong Answer
time: 14ms
memory: 63252kb

input:

1000000 3000 6000
0 1 1 1860
0 1 2 51
0 1 3 61
0 1 4 2721
0 1 5 596
0 1 6 2173
0 1 7 974
0 1 8 1525
0 1 9 706
0 1 10 451
0 1 11 2075
0 1 12 812
0 1 13 1117
0 1 14 299
0 1 15 2099
0 1 16 1521
0 1 17 2285
0 1 18 375
0 1 19 2894
0 1 20 1208
0 1 21 614
0 1 22 924
0 1 23 1670
0 1 24 867
0 1 25 2291
0 1 2...

output:

2995 2995 1939 2995 1727 2043 2019 1634 2995 1606 2995 2443 1614 2215 2912 2995 1582 2784 2384 1811 1611 2178 1625 2708 2995 2038 2995 1685 1922 1839 2880 2995 2104 1855 2980 2020 2091 1532 2106 2995 1867 2230 2607 1593 2930 1814 2597 2995 2282 1772 2126 2445 1884 2995 1705 1695 2288 2321 1920 2995 ...

result:

wrong answer 1st numbers differ - expected: '1495', found: '2995'

Test #5:

score: 10
Accepted
time: 78ms
memory: 142308kb

input:

40000 10000 20000
1 1 1 1
0 1 1 2
0 1 1 3
0 2 3 4
0 2 3 5
0 3 5 6
0 3 5 7
0 4 7 8
0 4 7 9
0 5 9 10
0 5 9 11
0 6 11 12
0 6 11 13
0 7 13 14
0 7 13 15
0 8 15 16
0 8 15 17
0 9 17 18
0 9 17 19
0 10 19 20
0 10 19 21
0 11 21 22
0 11 21 23
0 12 23 24
0 12 23 25
0 13 25 26
0 13 25 27
0 14 27 28
0 14 27 29
0 ...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 10000 numbers

Test #6:

score: 0
Wrong Answer
time: 104ms
memory: 159144kb

input:

40000 10000 20000
0 39999 2589 1050
1 39998 2589 983
0 39999 4308 9484
1 39998 4308 2423
0 39999 7924 4021
1 39998 7924 5520
0 39999 8340 2926
1 39998 8340 5694
0 39999 4146 8898
1 39998 4146 8588
0 39999 3838 2397
1 39998 3838 4545
0 39996 9766 4308
1 39995 9766 6570
0 39996 4764 8340
1 39995 4764 ...

output:

9858 8928 0
0
9127 9689 0
0
7812 9194 8374 9998 8589 9038 7833 0
8215 8784 8730 0
0
9998 8334 7928 9171 8159 7892 7707 8544 8428 8794 9998 7867 0
8004 7796 0
0
0
9428 9863 9179 7829 0
7829 8010 9585 8206 0
8362 8777 0
8827 0
9394 9857 0
7781 0
8253 7958 8932 7969 8218 0
8873 7833 9998 7817 9498 7894...

result:

wrong answer 1st numbers differ - expected: '7771', found: '9858'

Test #7:

score: 0
Wrong Answer
time: 889ms
memory: 400136kb

input:

1000000 30000 60000
0 999999 18959 18261
1 999998 18959 19279
0 999996 6700 18959
1 999995 6700 2151
0 999996 19778 18959
1 999995 19778 12268
0 999993 8449 6700
1 999992 8449 29787
0 999993 14350 6700
1 999992 14350 21702
0 999993 9759 6700
1 999992 9759 23907
0 999990 18560 9759
1 999989 18560 227...

output:

24082 28552 0
0
27809 0
26289 26530 29998 24101 25500 25127 27605 23462 23511 23693 26311 25637 25616 26262 26044 29276 29249 0
26084 26502 24111 27928 23384 0
23370 26072 23643 0
24126 25330 0
27789 29999 0
25422 29320 25879 24558 28508 26778 26333 26532 23595 23790 0
0
0
24939 0
26336 23836 23975 ...

result:

wrong answer 1st numbers differ - expected: '23311', found: '24082'

Test #8:

score: 10
Accepted
time: 1192ms
memory: 462120kb

input:

1000000 40000 80000
1 1 1 1
0 1 1 2
0 1 1 3
0 2 3 4
0 2 3 5
0 3 5 6
0 3 5 7
0 4 7 8
0 4 7 9
0 5 9 10
0 5 9 11
0 6 11 12
0 6 11 13
0 7 13 14
0 7 13 15
0 8 15 16
0 8 15 17
0 9 17 18
0 9 17 19
0 10 19 20
0 10 19 21
0 11 21 22
0 11 21 23
0 12 23 24
0 12 23 25
0 13 25 26
0 13 25 27
0 14 27 28
0 14 27 29
...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 40000 numbers

Test #9:

score: 0
Time Limit Exceeded

input:

1000000 50000 100000
0 999999 18845 16698
1 999998 18845 7793
0 999999 30202 25942
1 999998 30202 39321
0 999999 10014 42307
1 999998 10014 16269
0 999999 5779 8262
1 999998 5779 48787
0 999996 38679 5779
1 999995 38679 17636
0 999996 33436 5779
1 999995 33436 7042
0 999996 11608 5779
1 999995 11608...

output:


result:


Test #10:

score: 0
Wrong Answer
time: 1989ms
memory: 500616kb

input:

1000000 50000 100000
0 1 1 41380
0 1 2 36609
0 1 3 25332
0 1 4 39173
0 1 5 37591
0 1 6 49880
0 1 7 33261
0 1 8 29353
0 1 9 33900
0 1 10 3182
0 1 11 38944
0 1 12 8610
0 1 13 4518
0 1 14 21812
0 1 15 325
0 1 16 47816
0 1 17 21494
0 1 18 14930
0 1 19 2669
0 1 20 46226
0 1 21 17334
0 1 22 1388
0 1 23 29...

output:

28415 47340 27116 40337 38537 28659 29690 31719 29438 49995 31026 47010 32497 25680 49995 29558 40326 39207 43600 30613 38290 34901 49995 34797 49995 47447 43004 38544 25102 49995 49995 44928 47140 27026 42600 36092 25309 29993 35126 30682 49995 43617 25939 25815 43482 26632 29603 34930 31603 34712 ...

result:

wrong answer 1st numbers differ - expected: '24998', found: '28415'