620C - Pearls in a Row - CodeForces Solution


greedy *1500

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define int long long
#define ios ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define fi first
#define se second
#define endl "\n"
#define YES return cout << "YES" << endl, void()
#define NO return cout << "NO" << endl, void()
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
const double PI = acos(-1);
const double eqa = (1+sqrt(5.0))/2.0;
const int mod = 1000000007, inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int dx[] = {0, 1, 0, -1, -1, 1, 1, -1};
int dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
int gcd(int x, int y) {return y ? gcd(y, x % y) : x;}
int qmi(int a, int k, int p){int res = 1;while (k){if (k & 1) res = (LL)res * a % p;a = (LL)a * a % p;k >>= 1;}return res;}
int read(){int x = 0, f = 1;char ch = getchar();while (ch < '0' || ch > '9'){if (ch == '-') f = -1; ch = getchar();}
while (ch >= '0' && ch <= '9'){x = x * 10 + ch - '0'; ch = getchar();}return x * f;}

const int N = 300010;

int n;
int a[N];

void solve()
{
	cin >> n;
	vector<int> res;
	res.push_back(0);
	map<int, int> mp;
	for ( int i = 1; i <= n; i ++ ) {
		int x;
		cin >> x;
		mp[x] ++;
		if (mp[x] > 1) {
			res.push_back(i);
			mp.clear();
		}
	}
	if (res.size() == 1) cout << -1 << endl;
	else {
		res[res.size() - 1] = n;
		cout << res.size() - 1 << endl;
		for ( int i = 1; i < res.size(); i ++ ) {
			cout << res[i - 1] + 1 << " " << res[i] << endl; 
		}
	}
}

signed main()
{
	ios;
	int t = 1;
	// cin >> t;
	while (t --)
	{
		solve();
	}
	return 0;
}


Comments

Submit
0 Comments
More Questions

118D - Caesar's Legions
1598A - Computer Game
1605A - AM Deviation
1461A - String Generation
1585B - Array Eversion
1661C - Water the Trees
1459A - Red-Blue Shuffle
1661B - Getting Zero
1661A - Array Balancing
1649B - Game of Ball Passing
572A - Arrays
1455A - Strange Functions
1566B - MIN-MEX Cut
678C - Joty and Chocolate
1352E - Special Elements
1520E - Arranging The Sheep
1157E - Minimum Array
1661D - Progressions Covering
262A - Roma and Lucky Numbers
1634B - Fortune Telling
1358A - Park Lighting
253C - Text Editor
365B - The Fibonacci Segment
75A - Life Without Zeros
1519A - Red and Blue Beans
466A - Cheap Travel
659E - New Reform
1385B - Restore the Permutation by Merger
706A - Beru-taxi
686A - Free Ice Cream