-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDivisible interval.cpp
More file actions
56 lines (54 loc) · 1.2 KB
/
Divisible interval.cpp
File metadata and controls
56 lines (54 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// https://www.eolymp.com/en/problems/11342
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
signed main()
{
fastio;
int n;
cin >> n;
vector<int> a(n), pref(n);
map<int, int> ind;
for (int i = 0; i < n; i++)
{
cin >> a[i];
a[i] = a[i] % n;
if (i == 0)
{
pref[i] = a[i];
}
else
{
pref[i] = pref[i - 1] + a[i];
}
if (ind[pref[i]] == 0)
{
ind[pref[i]] = i + 1;
}
}
for (int i = 0; i < n; i++)
{
if (pref[i] % n == 0)
{
cout << 1 << " " << i + 1;
return 0;
}
else if (ind[pref[i] % n] > 0 && ind[pref[i] % n] < i + 1)
{
cout << ind[pref[i] % n] + 1 << " " << i + 1;
return 0;
}
else if (ind[pref[i]] > 0 && ind[pref[i]] < i + 1)
{
cout << ind[pref[i]] + 1 << " " << i + 1;
return 0;
}
}
cout << -1 << " " << -1;
return 0;
}