麦睿生 • 3个月前
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2000086;
struct enkidu {
int color, cost;
}a[maxn];
int n, k, p;
int color_cnt[60], color_last[60];
int color_num[60];
int last_acc;
int ans = 0;
bool vis[maxn];
inline int read() {
int x = 0, y = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') y = -1;
ch = getchar();
}
while(isdigit(ch)) {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * y;
}
int main() {
memset(color_cnt, 0, sizeof(color_cnt));
memset(color_num, 0, sizeof(color_num));
n = read(), k = read(), p = read();
for(int i = 1; i <= n; ++i)
a[i].color = read(), a[i].cost = read();
for(int i = 1; i <= n; ++i) {
int cl = a[i].color;
if(a[i].cost <= p) last_acc = i;
if(vis[cl]) {
if(color_last[cl] <= last_acc)
color_num[cl] = color_cnt[cl];
color_last[cl] = i;
ans += color_num[cl];
color_cnt[cl]++;
}
else if(!vis[cl]) {
color_last[cl] = i;
color_cnt[cl]++;
vis[cl] = 1;
}
}
cout << ans << '\n';
return 0;
}
评论: