`
java-mans
  • 浏览: 11414093 次
文章分类
社区版块
存档分类
最新评论

Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E - Cubes

 
阅读更多

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;

#ifdef _WIN32
#define i64 __int64
#define out64 "%I64d\n"
#define in64 "%I64d"
#else
#define i64 long long
#define out64 "%lld\n"
#define in64 "%lld"
#endif

#define FOR(i,a,b)      for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a)         for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a)        for( int i = (a)-1 ; i >= 0 ; i --)
#define S64(a)          scanf(in64,&a)
#define SS(a)           scanf("%d",&a)
#define LL(a)           ((a)<<1)
#define RR(a)           (((a)<<1)+1)
#define SZ(a)           ((int)a.size())
#define PP(n,m,a)       puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");}
#define pb              push_back
#define CL(Q)           while(!Q.empty())Q.pop()
#define MM(name,what)   memset(name,what,sizeof(name))
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)

const int inf = 0x3f3f3f3f;
const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double oo = 10e9;
const double eps = 10e-10;
const double pi = acos(-1.0);

i64 gcd(i64 _a, i64 _b)
{
    if (!_a || !_b)
    {
        return max(_a, _b);
    }
    i64 _t;
    while (_t = _a % _b)
    {
        _a = _b;
        _b = _t;
    }
    return _b;
};

i64 ext_gcd (i64 _a, i64 _b, i64 &_x, i64 &_y)
{
    if (!_b)
    {
        _x = 1;
        _y = 0;
        return _a;
    }
    i64 _d = ext_gcd (_b, _a % _b, _x, _y);
    i64 _t = _x;
    _x = _y;
    _y = _t - _a / _b * _y;
    return _d;
}

i64 invmod (i64 _a, i64 _p)
{
    i64 _ans, _y;
    ext_gcd (_a, _p, _ans, _y);
    _ans < 0 ? _ans += _p : 0;
    return _ans;
}

const int maxn = 201111;

int now[maxn];
int cont[maxn];
int next[maxn];
int ans[maxn];
int a[maxn];
int have[maxn];

int n,m,k;




int main()
{
    cin>>n>>m>>k;
    MM(ans,0);
    MM(next,0);
    MM(now,0);
    MM(have,0);
    MM(cont,0);

    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }

    for(int pos=1;pos <= n;pos++)
    {
        int c = a[pos];
        if(!now[c])
        {
            now[c] = pos;
            ans[c] = 1;
            have[c] = 1;
            cont[c] = pos;
        }
        else
        {
            next[now[c]] = pos;
            now[c] = pos;
            while(true)
            {
                int temp = pos - cont[c] - have[c];
                if(temp<=k)
                {
                    have[c]++;
                    ans[c] = max(ans[c],have[c]);
                    break;
                }
                else
                {
                    if(next[cont[c]])
                    {
                        cont[c] = next[cont[c]];
                        have[c]--;
                    }
                    else
                    {
                        have[c] = 1;
                        break;
                    }
                }
            }
        }
    }
    int final=0;
    for(int i=1;i<=m;i++)
    {
        final = max(final,ans[i]);
    }

    cout<<final<<endl;
    system("pause");
    return 0;
}


分享到:
评论

相关推荐

    Codeforces Round #723 (Div. 2).md

    Codeforces Round #723 (Div. 2).md

    Codeforces Round #629 (Div. 3) B. K-th Beautiful String

    长度为n的字符串包含n−2n−2n−2个aaa和222个bbb,求按照字典序排列输出第kkk个字符串 解题思路 第一个bbb在倒数第二位有1个字符串,在倒数第三位有2个字符串…在倒数第nnn位时有n−1n-1n−1个字符串 可以根据第一...

    Codeforces Round #630 (Div. 2) D. Walk on Matrix(构造)

    上面代码跑出来的dp[n][m]是0,然后从(1,1)(1,2)(2,2)(2,3)这样的相与值是k (看懂ans+k是啥应该就懂了) 代码: int main() { std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0); int ans=(1&...

    Codeforces Round #627 (Div. 3) C. Frog Jumps(思维)

    传送门 题意: 开始位置在0,问能否跳到n+1位置 每步只能跳d 在1——n每个位置有方向,L,R,求d的最小值 思路: 只用找相邻两个R之间的最大值即可 代码: #include #include ...typedef long long l

    Codeforces Round #627 (Div. 3) B. Yet Another Palindrome Problem

    就是把所有相等的数放到一个vector里,如果他出现大于2次,看最远的间距是否大于2即可,找到一个就可以 代码: #include #include #include #include #include #include #include #include #include #include #...

    Codeforces Round #479 (Div. 3) E. Cyclic Components

    E. Cyclic Components 题目链接-E. Cyclic Components 题目大意 给你nnn个点和mmm条边,求所构成图中单圈环的个数 解题思路 并查集并查集并查集 很明显单圈环每个点的度都为222,所以我们可以用数组cnt[]记录每...

    Codeforces Round #629 (Div. 3) E.Tree Queries (DFS)

    Codeforces Round #629 (Div. 3) E.Tree Queries (DFS) 思路:若ai 在路径上 ,则ai的父结点一定在路径上,若ai是路径上某个结点的子结点,则ai的父结点一定在路径上,综上只需考虑ai的父节点就行了。对每个ai判断...

    Codeforces Round #628 (Div. 2)

    给两两节点放一个数字(0~n-2 唯一) 给你一棵树,求所有任意两节点相连的路以外的路上的数字的最小值最小 思路 构造 若一个点连了三条边及以上,则这个点的边从最小值开始赋值。其他边从最大点开始赋值。 证明:一...

    Codeforces Round #628 (Div.2) C.Ehab and Path-etic MEXs(树,思维)

    传送门 题意: 给一颗n个结点的数,然后n-1条边,我们要做的...如果不是一条链,那肯定有个结点的度大于等于3,把这个结点周围的三条边分别给值0,1,2,这样所有MEX(u,v)最大值为2,因为不可能有一条边同时经过0,1,2这三

    Codeforces Round #628 (Div. 2) A. EhAb AnD gCd

    输入一个正整数x,找出这样的2个正整数a和b,使得gcd(a,b)+lcm(a,b)=x 解题思路 找最特殊的情况a=1,b=x-1即可 这样a,b两个数最大公因数为1,最小公倍数x-1,满足题意√ 附上代码 #include #define int long long #...

    Codeforces Round #624 (Div. 3) F. Moving Points /详解

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output There are n points on a coordinate axis OX. The i-th point is located at the integer point xi ...

    Codeforces Round #620 (Div. 2) Longest Palindrome

    B. Longest Palindrome time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Returning back to problem solving, Gildong is now studying about ...

    Codeforces Round #635 (Div. 2)D. Xenia and Colorful Gems

    传说门 刚好今晚是中国场! 其实这道题比较水,但当时思路错,一心想着化简公式,浪费了好多时间a....#pragma GCC optimize(2) #include #define ll long long #define endl '\n' using namespace std; const int manx=

    Codeforces Round #628 (Div. 2) A~~D

    A #include using namespace std; typedef long long ll; int main(){ int t; cin&gt;&gt;t; while(t--){ ll x; cin&gt;&gt;x; cout&lt;&lt;1&gt;&gt;t; while(t--){ st.clear(); ll n; cin &gt;&gt;n;... ll re

    Codeforces Round #628 (Div. 2)【A B C D】

    传送门 A. EhAb AnD gCd 直接输出1,n-1即可 #include #include #include #include #include #include #include #include #include #include #define pb push_back #define lb lower_bound ...con

    Codeforces Round #633 (Div. 2) A. Filling Diamonds(找规律)

    传送门 题意: 找规律,题意就是有多少种方式填充该图形 画两个就发现,输出n即可 代码: #include #include #include #include #include #include #include #include ...#define SZ(x) ((int)(x)

    【Codeforces Round#620 (Div. 2)】B. Longest Palindrome 题解

    题目链接:B. Longest Palindrome 题目 Returning back to problem solving, Gildong is now studying about palindromes. He learned that a palindrome is a string that is the same as its reverse....

    Codeforces Round #627 (Div. 3) A. Yet Another Tetris Problem

    给一个长度为n的数组,两种操作,一个是把任意一个ai变成ai+2a_i变成a_i+2ai​变成ai​+2,另一个是如果所有数都大于0,可以把所有数减1,问通过这些操作能否把所有数变为0 思路: 如果任意两个数之差为奇数,那么就...

Global site tag (gtag.js) - Google Analytics