写点简单的思维题
https://codeforces.com/problemset/problem/1927/D
思路:用两个数组,一个存储原始数据,一个用nex存该位置第一次不一样的下标
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
int nex[200010];
int alst[200010];
int main()
{
int t; cin >> t;
int nn = 0;
for (int iii = 0; iii < t; iii++)
{
memset(nex, 0, sizeof(nex));
memset(alst, 0, sizeof(alst));
nn = 0;
int n; cin >> n;
for (int i = 0; i < n; i++) {
cin >> alst[i];
if (i > 0 and alst[i] != alst[i - 1])
{
nex[nn] = i;
nn = i;
}
}
for (int i = 1; i < n; i++)
{
if (alst[i] == alst[i - 1])
nex[i] = nex[i - 1];
}
int tt; cin >> tt;
for (int ii = 0; ii < tt; ii++)
{
int l, r;
cin >> l >> r;
l--, r--;
if (nex[l] > r or nex[l] == 0)cout << "-1 -1" << endl;//这里不能落了nex[l] == 0的判断,因为还有可能根本就不存在这个数,当然也可以把都是0的拿length替换,思路不变
else cout << nex[l]+1 << ' ' << l+1 << endl;//注意这里的下标
}
cout << endl;
}
return 0;
}
标签:Different,nn,int,alst,Codeforces,cin,nex,include,Round
From: https://www.cnblogs.com/zzzsacmblog/p/18083874