Educational Codeforces Round 7

Educational Codeforces Round 7

2月11号


A - Infinite Sequence

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f
 LL n;
 LL l,r;
int main()
{
    while(scanf("%I64d",&n)!=EOF)
    {
        l=1LL;r=1LL;
        for(LL i=2LL;  ; i++)
        {
            r=l+i;
            if(r>=n)
            {
                break;
            }
            l=r;
        }
        printf("%I64d
",n-l);
    }
    return 0;
}

C - Not Equal on a Segment

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define INF 0x3f3f3f3f3f3f
int a[2*100000+100];
int p[2*100000+100];
int n,m;
int li,ri,xi;
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==a[i-1]) p[i]=p[i-1];
            else p[i]=i-1;
        }
        while(m--)
        {
            scanf("%d%d%d",&li,&ri,&xi);
            if(a[ri]==xi)
                if(p[ri]>=li) printf("%d
",p[ri]);
                else printf("-1
");
            else
                printf("%d
",ri);
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/zzulipomelo/p/5186269.html