Educational Codeforces Round 58 Div. 2 自闭记

  明明多个几秒就能场上AK了。自闭。

  A:签到。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int T,l,r,d;
signed main()
{
/*#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif*/
    T=read();
    while (T--)
    {
        l=read(),r=read(),d=read();
        if (d<l) cout<<d<<endl;
        else cout<<1ll*(r/d+1)*d<<endl;
    }
    return 0;
    //NOTICE LONG LONG!!!!!
}

  B:签到。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 500010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n;
char s[N];
signed main()
{
/*#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif*/
    scanf("%s",s+1);n=strlen(s+1);
    bool flag=0;int x=n+1,y=0;
    for (int i=1;i<=n;i++)
    {
        if (s[i]==‘[‘) flag=1;
        if (s[i]==‘:‘) if (flag) {x=i;break;}
    }
    flag=0;
    for (int i=n;i>=1;i--)
    {
        if (s[i]==‘]‘) flag=1;
        if (s[i]==‘:‘) if (flag) {y=i;break;}
    }
    if (x>=y) cout<<-1;
    else
    {
        int ans=4;
        for (int i=x+1;i<y;i++)
        if (s[i]==‘|‘) ans++;
        cout<<ans;
    }
    return 0;
    //NOTICE LONG LONG!!!!!
}

  C:wa了无数发。按左端点排序后找一个连续且和其他线段不相交的线段集即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 100010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int T,n,ans[N];
struct data
{
    int l,r,i;
    bool operator <(const data&a) const
    {
        return l<a.l;
    }
}a[N];
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    T=read();
    while (T--)
    {
        n=read();
        for (int i=1;i<=n;i++) a[i].l=read(),a[i].r=read(),a[i].i=i;
        sort(a+1,a+n+1);
        bool flag=0;a[n+1].l=100000000;
        int t=1,x=a[1].r;
        while (t<n&&a[t+1].l<=x) t++,x=max(x,a[t].r);
        if (t==n) cout<<-1<<endl;
        else
        {
            for (int i=1;i<=t;i++) ans[a[i].i]=1;
            for (int i=t+1;i<=n;i++) ans[a[i].i]=2;
            for (int i=1;i<=n;i++) printf("%d ",ans[i]);
            cout<<endl;
        }
    }
    return 0;
    //NOTICE LONG LONG!!!!!
}

  E:这才是真签到吧?wa了一发自闭啊?

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 500010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int m,u,v;
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    m=read();
    while (m--)
    {
        char c=getchar();while (c!=‘+‘&&c!=‘?‘) c=getchar();
        int x=read(),y=read();if (x>y) swap(x,y);
        if (c==‘+‘)
        {
            u=max(u,x),v=max(y,v);
        }
        else
        {
            if (x>=u&&y>=v) printf("YES\n");
            else printf("NO\n");
        }
    }
    return 0;
    //NOTICE LONG LONG!!!!!
}

  D:如果路径经过某点,最后所得的路径gcd显然是该点某些质因子的倍数。对此dp即可。一发wa on 3,3可是样例啊?自闭了啊?

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,a[N],p[N],f[N][30],prime[N][30],t,ans;
struct data{int to,nxt;
}edge[N<<1];
void addedge(int x,int y){t++;edge[t].to=y,edge[t].nxt=p[x],p[x]=t;}
void dfs(int k,int from)
{
    for (int i=p[k];i;i=edge[i].nxt)
    if (edge[i].to!=from)
    {
        dfs(edge[i].to,k);
        for (int x=1;x<=prime[edge[i].to][0];x++)
            for (int y=1;y<=prime[k][0];y++)
            if (prime[edge[i].to][x]==prime[k][y])
            {
                ans=max(ans,f[k][y]+f[edge[i].to][x]+1);
                f[k][y]=max(f[k][y],f[edge[i].to][x]+1);
            }
    }
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    n=read();
    for (int i=1;i<=n;i++) a[i]=read();
    bool flag=1;
    for (int i=1;i<=n;i++) if (a[i]!=1) flag=0;
    if (flag) {cout<<0;return 0;}
    for (int i=1;i<n;i++)
    {
        int x=read(),y=read();
        addedge(x,y),addedge(y,x);
    }
    for (int i=1;i<=n;i++)
    {
        for (int j=2;j*j<=a[i];j++)
        if (a[i]%j==0)
        {
            prime[i][++prime[i][0]]=j;
            while (a[i]%j==0) a[i]/=j;
        }
        if (a[i]>1) prime[i][++prime[i][0]]=a[i];
    }
    dfs(1,1);
    cout<<ans+1;
    return 0;
    //NOTICE LONG LONG!!!!!
}

  G:一眼线性基,然后就往别的方面想了。自闭了半天直接乱搞求个前缀和搞了个线性基上去就pp了。冷静了半天正确性何在。事实上划分序列相当于选出一些前缀和,这是一个裸到不行的线性基。注意虽然最后一个前缀和应该是必须选的,但是不考虑也不会造成什么影响(吧)。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,a[N],base[32],ans;
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    n=read();
    for (int i=1;i<=n;i++) a[i]=a[i-1]^read();
    if (a[n]==0) {cout<<-1;return 0;}
    for (int i=1;i<=n;i++)
        for (int j=30;~j;j--)
        if (a[i]&(1<<j))
        {
            if (base[j]) a[i]^=base[j];
            else {base[j]=a[i],ans++;break;}
        }
    cout<<ans;
    return 0;
    //NOTICE LONG LONG!!!!!
}

  F:随便都知道是二分答案。但是nmlog显然有些吃力。考虑random_shuffle一发,每次记录当前需要的最大容量,考虑下一辆卡车时先判断当前容量是否能满足其需求,如果不行再二分一下。这样复杂度大约是nm+nlogmlogV,因为只需要对所需容量的单调栈中的卡车进行二分,而排列又是随机的。复杂度证明似乎在一篇cfblog里看到过。(突然发现整个idea都在这篇blog里https://codeforces.com/blog/entry/62602)一开始又没注意到要开long long,交一发in queue了半天,然后wa on 3,结果改了一发又没改全,交一发再次in queue了半天,接着wa on 3。然后就只剩20s了,手速不行,就,自闭了。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<ctime>
using namespace std;
#define ll long long
#define N 410
#define M 250010
char getc(){char c=getchar();while ((c<‘A‘||c>‘Z‘)&&(c<‘a‘||c>‘z‘)&&(c<‘0‘||c>‘9‘)) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
    int x=0,f=1;char c=getchar();
    while (c<‘0‘||c>‘9‘) {if (c==‘-‘) f=-1;c=getchar();}
    while (c>=‘0‘&&c<=‘9‘) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x*f;
}
int n,m,a[N];
ll ans;
struct data{int s,f,c,r;
}b[M];
bool check(ll k,int i)
{
    ll cur=k;int cnt=0;
    for (int j=b[i].s;j<b[i].f;j++)
    {
        if (cur>=1ll*b[i].c*(a[j+1]-a[j])) cur-=1ll*b[i].c*(a[j+1]-a[j]);
        else
        {
            cur=k,cnt++;
            if (cur>=1ll*b[i].c*(a[j+1]-a[j])) cur-=1ll*b[i].c*(a[j+1]-a[j]);
            else return 0;
        }
        if (cnt>b[i].r) return 0;
    }
    return 1;
}
signed main()
{
#ifndef ONLINE_JUDGE
    freopen("b.in","r",stdin);
    freopen("b.out","w",stdout);
    const char LL[]="%I64d\n";
#endif
    srand(time(0));
    n=read(),m=read();
    for (int i=1;i<=n;i++) a[i]=read();
    for (int i=1;i<=m;i++) b[i].s=read(),b[i].f=read(),b[i].c=read(),b[i].r=read();
    random_shuffle(b+1,b+m+1);
    for (int i=1;i<=m;i++)
    if (!check(ans,i))
    {
        ll l=ans+1,r=1000000000000000000ll;
        while (l<=r)
        {
            ll mid=l+r>>1;
            if (check(mid,i)) ans=mid,r=mid-1;
            else l=mid+1;
        }
    }
    cout<<ans;
    return 0;
    //NOTICE LONG LONG!!!!!
}

原文地址:https://www.cnblogs.com/Gloid/p/10258416.html

时间: 2024-11-02 11:11:35

Educational Codeforces Round 58 Div. 2 自闭记的相关文章

Codeforces Round #545 Div. 1自闭记

A:求出该行该列各有多少个比其小的取max,该行该列各有多少个比其大的取max,加起来即可. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm> using namespace std; #define ll long long #define N 1010 char ge

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html

Educational Codeforces Round 58 (Rated for Div. 2) (题解)

C题卡了一个小时, 又被教育场教育了... A. Minimum Integer 大意:求不在$[l,r]$范围内的最小被$d$整除的数 模拟 #include <iostream> #define REP(i,a,n) for(int i=a;i<=n;++i) using namespace std; int main() { int t; scanf("%d", &t); REP(i,1,t) { int l,r,d; scanf("%d%d%

Educational Codeforces Round 58 (Rated for Div. 2) (前两题题解)

感慨 这次比较昏迷最近算法有点飘,都在玩pygame...做出第一题让人hack了,第二题还昏迷想错了 A Minimum Integer(数学) 水题,上来就能做出来但是让人hack成了tle,所以要思考一下具体的过程 原本我是认为直接把d进行累加看什么时候不在那个segment内也就是那个范围之内结果tle 今天思考一下发现有两种情况 ①如果d本来就是小于左边界的那么就输出d就可以了,因为样例明确提示有原来的数也可以 ②然后就是如果d在范围之内或者范围外可以用余数来确定具体的数公式是: an

Educational Codeforces Round 58 (Rated for Div. 2)

A. Minimum Integer 水 #include<bits/stdc++.h> #define clr(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long ll; const int maxn=1e3+10; struct node{ ll num,mag; friend bool operator <(const node &a,const node &b){ return a.m

Educational Codeforces Round #54 (Div. 2) E. Vasya and a Tree 技巧題

題目連接:http://codeforces.com/contest/1076/problem/E 本題大意: 給一棵根節點為"1"樹,給m個操作,每個操作三個整數,v,d,x,意思是從節點1,往下深度d,遍及的節點的值都加上x,d可能是0,就是只加在自己上.結束m個操作后輸出每個節點的值. 解題思路: 這裡不應該考慮同時操作整棵樹.因為每個節點的子樹是多樣的,而應該以dfs的形式,直接搜到葉子節點,這樣沿途就是一條鏈.每時每刻都在操作一條鏈,也就是一段區間.這樣操作轉化為:一個節點往

Educational Codeforces Round 47(Div 2)(A~D)

比赛链接 A.Game Shopping 这种题真是..打开网页1min 读题3min 思考0min 写代码0.5min.. #include <cstdio> #include <cctype> #include <algorithm> #define gc() getchar() const int N=1e3+5; int n,m,cost[N],A[N]; inline int read() { register int now=0;register char

educational codeforces round 58 (div2) D. GCD Counting

这道题每个节点都由子节点的不同状态转移过来,只要子节点可以整除这个节点的的某个质因子,就可以转移.为了遍历找到本节点的质因子对应于这个节点子节点的哪些状态,需要开个map<pair<int,int> ,int>来存储 #include<bits/stdc++.h> using namespace std; typedef pair<int,int> P; vector<int> G[200001]; vector<int> vec[2

Educational Codeforces Round 80 (Div. 2)

D. Minimax Problem 题意 && 思路 题意: 给出 n 个长度为 m 的序列(1 ≤ n ≤ 3*1e5, 1≤ m ≤8 ),对于序列中的每一个元素 a,(0≤a≤1e9) 现在你要求出,对于所有任意两行序列为一组(或则自己本身成为一组),进行(两个序列的同一个位置取最大值放到新序列中)操作形成新的序列,再从新的序列中选取最小值作为ans,最后要对所有可能组成的ans中输出最大的ans. 思路: 说实话没有想到用二分加二进制压缩表示来求解.二分倒是可以想到,毕竟正向 把