【gdsoi2018 day3】誰是冠軍

來源:互聯網
上載者:User
題目大意:

不說。 題解:

如果x能勝y,則x往y連一條邊。

如果一個點能夠遍曆所有的點,顯然它就是可以的。

用tarjan縮一下強聯通分量,入度為0的那個分量就是答案。

這樣就有60分。

用主席樹最佳化一下連邊。

大概是線段樹區間會下放到log個完整區間,直接往那些區間連邊。

那些區間往包含的點連邊。

注意插入有時效性,所以要用主席樹的那種思想,新開點。

#include<cstdio>#include<algorithm>#define fo(i, x, y) for(int i = x; i <= y; i ++)#define min(a, b) ((a) < (b) ? (a) : (b))using namespace std;const int N = 1e5 + 5, M = 1e7 + 2e6, D = 6e6;int n, td, c[N], d[M];struct node {    int i, a, b, c;} a[N];int c1(node a, node b) {return a.a < b.a;}int c2(node a, node b) {return a.b < b.b;}int c3(node a, node b) {return a.c < b.c;}int final[D], next[M], to[M], tot, rt;void link(int x, int y) {next[++ tot] = final[x], to[tot] = y, final[x] = tot;}int pl, pr, px;struct tree {    int l, r;} t[D];void fi(int &i, int x, int y) {    if(y < pl || x > pr) return;    if(!i) return;    if(x >= pl && y <= pr) {link(px, i); return;}    int m = x + y >> 1;    fi(t[i].l, x, m); fi(t[i].r, m + 1, y);}void add(int &i, int x, int y) {    if(y < pl || x > pr) return;    t[++ td] = t[i];    link(td, px); if(i) link(td, i);    i = td;    if(x == y) return;    int m = x + y >> 1;    add(t[i].l, x, m); add(t[i].r, m + 1, y);}void GG() {    rt = 0;    fo(i, 1, n) {        pl = 1; pr = c[i] - 1; px = d[i];        fi(rt, 1, n);        pl = pr = c[i]; px = d[i];        add(rt, 1, n);    }}int win(int i, int j) {    return (a[i].a > a[j].a) + (a[i].b > a[j].b) + (a[i].c > a[j].c);}int dfn[D], low[D], tt, fa[D], tf, bd[D];int zx[M], zi[M], z0;bool bz[M];void dg(int x) {    zx[z0 = 1] = x; bz[z0] = 0;    int ti;    while(z0) {        ti = 0; x = zx[z0];        if(bz[z0]) {            int i = zi[z0]; low[x] = min(low[x], low[to[i]]);            for(i = next[i]; i; i = next[i]) {                int y = to[i];                if(!dfn[y]) {                    zi[z0] = i; bz[z0] = 1;                    ++ z0;                    zx[z0] = y; bz[z0] = 0;                    ti = 1; break;                } else {                    if(bd[y]) low[x] = min(low[x], dfn[y]);                }            }            if(ti) continue;            if(dfn[x] == low[x]) {                tf ++;                do {                    fa[d[d[0]]] = tf; bd[d[d[0]]] = 0;                } while(d[d[0] --] != x);            }        } else {            dfn[x] = low[x] = ++ tt;            bd[x] = 1; d[++ d[0]] = x;            for(int i = final[x]; i; i = next[i]) {                int y = to[i];                if(!dfn[y]) {                    zi[z0] = i; bz[z0] = 1;                    ++ z0;                    zx[z0] = y; bz[z0] = 0;                    ti = 1; break;                } else {                    if(bd[y]) low[x] = min(low[x], dfn[y]);                }            }            if(ti) continue;            if(dfn[x] == low[x]) {                tf ++;                do {                    fa[d[d[0]]] = tf; bd[d[d[0]]] = 0;                } while(d[d[0] --] != x);            }        }        z0 --;    }}int main() {    freopen("champion.in", "r", stdin);    freopen("champion.out", "w", stdout);    scanf("%d", &n);    fo(i, 1, n) a[i].i = i, scanf("%d %d %d", &a[i].a, &a[i].b, &a[i].c);    sort(a + 1, a + n + 1, c1);    fo(i, 1, n) a[i].a = i;    sort(a + 1, a + n + 1, c2);    fo(i, 1, n) a[i].b = i;    sort(a + 1, a + n + 1, c3);    fo(i, 1, n) a[i].c = i;    td = n;    sort(a + 1, a + n + 1, c1);    fo(i, 1, n) c[i] = a[i].b, d[i] = a[i].i;    GG();    sort(a + 1, a + n + 1, c2);    fo(i, 1, n) c[i] = a[i].c, d[i] = a[i].i;    GG();    sort(a + 1, a + n + 1, c3);    fo(i, 1, n) c[i] = a[i].a, d[i] = a[i].i;    GG();    fo(i, 1, n) d[i] = i;    fo(i, 1, n - 1) if(win(d[i - 1], d[i])) swap(d[i - 1], d[i]);    int g = a[d[n]].i;    dg(g);    fo(i, 1, n) if(fa[i] == fa[g])        printf("%d\n", i);}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.