Educational Codeforces Round 7
Educational Codeforces Round 7
2月11号
#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",n-l);
}
return 0;
}
#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\n",p[ri]);
else printf("-1\n");
else
printf("%d\n",ri);
}
}
return 0;
}