|
|
|
@ -1,54 +1,47 @@
|
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
typedef pair<int, int> PII;
|
|
|
|
|
const int N = 110;
|
|
|
|
|
int a[N];
|
|
|
|
|
int st[10];
|
|
|
|
|
struct Node {
|
|
|
|
|
int st, ed;
|
|
|
|
|
};
|
|
|
|
|
vector<Node> q;
|
|
|
|
|
vector<PII> q;
|
|
|
|
|
int res;
|
|
|
|
|
/*
|
|
|
|
|
5
|
|
|
|
|
1 2 3 3 2
|
|
|
|
|
|
|
|
|
|
5
|
|
|
|
|
3 2 4 2 3
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
3 2 4 2 5 3 1
|
|
|
|
|
*/
|
|
|
|
|
int main() {
|
|
|
|
|
int n;
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
if (!st[a[i]]) {
|
|
|
|
|
st[a[i]] = 1;
|
|
|
|
|
for (int j = n; j; j--)
|
|
|
|
|
if (a[i] == a[j]) {
|
|
|
|
|
q.push_back({i, j});
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 从左到右枚举,所以,不再需再进行按左端点排序,现在就是按左端点排序完的
|
|
|
|
|
// Q:求一组区间的相交区间个数?如果存在一个相交区间,就多加1个1
|
|
|
|
|
res = q.size();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < q.size(); i++) cout << q[i].st << " " << q[i].ed << endl;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < q.size(); i++)
|
|
|
|
|
for (int j = i + 1; j < q.size(); j++) {
|
|
|
|
|
if (q[i].ed > q[j].st && q[j].ed > q[i].ed) {
|
|
|
|
|
res++;
|
|
|
|
|
#ifndef ONLINE_JUDGE
|
|
|
|
|
freopen("6.in", "r", stdin);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
while (cin >> n && n) {
|
|
|
|
|
// 各种清空
|
|
|
|
|
memset(a, 0, sizeof a);
|
|
|
|
|
memset(st, 0, sizeof st);
|
|
|
|
|
q.clear();
|
|
|
|
|
res = 0;
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组
|
|
|
|
|
for (int i = 1; i <= n; i++) { // 遍历每个位置
|
|
|
|
|
if (!st[a[i]]) { // 如果此数字没有被处理过
|
|
|
|
|
st[a[i]] = 1; // 标识已处理
|
|
|
|
|
for (int j = n; j; j--) // 从后向前找到它的终止位置
|
|
|
|
|
if (a[i] == a[j]) {
|
|
|
|
|
q.push_back({i, j}); // 记录有效区间
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cout << res << endl;
|
|
|
|
|
// 从左到右枚举,所以,不再需再进行按左端点排序,现在就是按左端点排序完的
|
|
|
|
|
// Q:求一组区间的相交区间个数?如果存在一个相交区间,就多加1个1
|
|
|
|
|
res = q.size();
|
|
|
|
|
|
|
|
|
|
// 如果存在区间相交,则res++
|
|
|
|
|
for (int i = 0; i < q.size(); i++)
|
|
|
|
|
for (int j = i + 1; j < q.size(); j++)
|
|
|
|
|
if (q[i].second > q[j].first && q[j].second > q[i].second) res++;
|
|
|
|
|
|
|
|
|
|
cout << res << endl;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|