【AtCoder】ARC069

ARC069

C - Scc Puzzle

……不说了

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 1005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int64 N,M;
void Solve() {
    read(N);read(M);
    if(N * 2 >= M) {out(M / 2);enter;}
    else {out(N + (M - N * 2) / 4);enter;}
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

D - Menagerie

容易发现固定两位后可以推出所有,枚举一下前两位是啥就行

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
char s[MAXN];
int num[MAXN];
void Solve() {
    read(N);
    scanf("%s",s);
    for(int i = 0 ; i <= 1 ; ++i) {
        for(int j = 0 ; j <= 1 ; ++j) {
            num[0] = i;num[1] = j;
            for(int k = 2 ; k < N ; ++k) {
                num[k] = (s[k - 1] == 'x') ^ num[k - 2] ^ num[k - 1];
            }
            int t0 = num[N - 1] ^ num[1] ^ num[0] ^ (s[0] == 'x');
            int tN = num[0] ^ num[N - 2] ^ num[N - 1] ^ (s[N - 1] == 'x');
            if(t0 == 0 && tN == 0) {
                for(int i = 0 ; i < N ; ++i) {
                    if(num[i] == 0) putchar('S');
                    else putchar('W');
                }
                enter;
                return;
            }
        }
    }
    puts("-1");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

E - Frequency

显然只有前缀最大值改变的位置会被统计

统计的方法是若从a变到b,我把b及以后所有的数大于a的全削成a是b的次数,统计起来可以直接把大于a的数全削成a,减去下一个位置大于b的数全削成b的次数

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 a[MAXN],b[MAXN],pre[MAXN],ans[MAXN];
map<int,int64> zz,num;
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {read(a[i]);b[i] = a[i];ans[1] += a[i];}
    sort(b + 1,b + N + 1);
    for(int i = N ; i >= 1 ; --i) {

        if(b[i] != b[i + 1]) {
            num[b[i]] += N - i;
            zz[b[i]] += zz[b[i + 1]];
        }
        num[b[i]]++;
        zz[b[i]] += b[i];
    }
    int pos = 1;
    for(int i = 1 ; i <= N ; ++i) {
        if(a[i] > pre[i - 1] && i != 1) {
            ans[i] += zz[pre[i - 1]] - pre[i - 1] * num[pre[i - 1]];
            ans[pos] -= ans[i];
            pos = i;
        }
        pre[i] = max(pre[i - 1],a[i]);
    }
    for(int i = 1 ; i <= N ; ++i) {
        out(ans[i]);enter;
    }
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

F - Flags

大意是N个旗子可以放两个位置,设d是旗子之间最小的间距,d最大是多少

很套路。。。直接线段树优化建图跑2-SAT

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct tr_node {
    int l,r,lc,rc;
}tr[MAXN * 10];
struct node {
    int to,next;
}E[MAXN * 100];
int sumE,head[MAXN * 10];
int Ncnt,N;
pii val[MAXN * 2];
int p[MAXN][2],pos[MAXN],rt,x[MAXN][2],tot;
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void build(int &u,int l,int r) {
    u = ++Ncnt;
    tr[u].l = l;tr[u].r = r;
    if(l == r) {pos[l] = u;return;}
    int mid = (l + r) >> 1;
    build(tr[u].lc,l,mid);
    build(tr[u].rc,mid + 1,r);
    add(u,tr[u].lc);add(u,tr[u].rc);
}

void Add_Range(int u,int l,int r,int v) {
    if(l > r) return;
    if(tr[u].l == l && tr[u].r == r) {add(v,u);return;}
    int mid = (tr[u].l + tr[u].r) >> 1;
    if(r <= mid) Add_Range(tr[u].lc,l,r,v);
    else if(l > mid) Add_Range(tr[u].rc,l,r,v);
    else {Add_Range(tr[u].lc,l,mid,v);Add_Range(tr[u].rc,mid + 1,r,v);}
}
int findL(int v) {
    int l = 1,r = tot;
    while(l < r) {
        int mid = (l + r) >> 1;
        if(x[val[mid].fi][val[mid].se] >= v) r = mid;
        else l = mid + 1;
    }
    return l;
}
int findR(int v) {
    int l = 1,r = tot;
    while(l < r) {
        int mid = (l + r + 1) >> 1;
        if(x[val[mid].fi][val[mid].se] <= v) l = mid;
        else r = mid - 1;
    }
    return l;
}
int dfn[MAXN * 10],low[MAXN * 10],sta[MAXN * 10],top,col[MAXN * 10],idx,instack[MAXN * 10],cor;
void Tarjan(int u) {
    dfn[u] = low[u] = ++idx;
    sta[++top] = u;
    instack[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
        int v = E[i].to;
        if(!dfn[v]) {
            Tarjan(v);
            low[u] = min(low[u],low[v]);
        }
        else if(instack[v] == 1) {
            low[u] = min(low[u],dfn[v]);
        }
    }
    if(low[u] == dfn[u]) {
        ++cor;
        while(1) {
            int x = sta[top--];
            col[x] = cor;
            instack[x] = 2;
            if(x == u) break;
        }
    }
}
bool check(int d) {
    Ncnt = 0,sumE = 0;
    memset(head,0,sizeof(head));
    build(rt,1,tot);
    for(int i = 1 ; i <= tot ; ++i) {
        int u = pos[i];
        p[val[i].fi][val[i].se ^ 1] = u;
    }
    for(int i = 1 ; i <= tot ; ++i) {
        int a,b;
        a = findL(x[val[i].fi][val[i].se] - d + 1);
        b = findR(x[val[i].fi][val[i].se] + d - 1);
        Add_Range(1,a,i - 1,p[val[i].fi][val[i].se]);
        Add_Range(1,i + 1,b,p[val[i].fi][val[i].se]);
    }
    idx = 0;top = 0;cor = 0;
    memset(dfn,0,sizeof(dfn));memset(low,0,sizeof(low));
    memset(col,0,sizeof(col));memset(instack,0,sizeof(instack));
    for(int i = 1 ; i <= N ; ++i) {
        if(!dfn[i]) Tarjan(i);
    }
    for(int i = 1 ; i <= N ; ++i) {
        if(col[p[i][0]] == col[p[i][1]]) return false;
    }
    return true;
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
        read(x[i][0]);read(x[i][1]);
        val[++tot] = mp(i,0);val[++tot] = mp(i,1);
    }
    sort(val + 1,val + tot + 1,[](pii a,pii b){return x[a.fi][a.se] < x[b.fi][b.se];});
    int l = 0,r = 1000000000;
    while(l < r) {
        int mid = (l + r + 1) >> 1;
        if(check(mid)) l = mid;
        else r = mid - 1;
    }
    out(l);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}

posted @ 2019-05-04 16:44  sigongzi  阅读(236)  评论(0编辑  收藏  举报