系列: Algorithms
c
55 行
· 更新於 2026-02-19
nationalities.c
Algorithms/nationalities.c
#include <stdio.h>
#include <stdlib.h>
#define MAXK 300005
#define MAXX 100005
#define WINDOW 86400
typedef struct {
int time;
int nationality;
} Passenger;
Passenger queue[MAXK];
int head = 0, tail = 0;
int freq[MAXX] = {0};
int distinct = 0;
int main() {
int n;
scanf("%d", &n);
int t, k, x;
int current_time = 0;
for (int i = 0; i < n; i++) {
scanf("%d %d", &t, &k);
current_time = t;
for (int j = 0; j < k; j++) {
scanf("%d", &x);
queue[tail].time = t;
queue[tail].nationality = x;
tail ++;
if (freq[x] == 0) {
distinct ++;
}
freq[x] ++;
}
while (head < tail && queue[head].time <= current_time - WINDOW) {
int nat = queue[head].nationality;
freq[nat] --;
if (freq[nat] == 0) {
distinct --;
}
head ++;
}
printf("%d\n", distinct);
}
return 0;
}
相關文章
Algorithms
java
更新於 2026-03-02
#include <iostream>.java
#include <iostream>.java — java source code from the Algorithms learning materials (Algorithms/#include <iostream>.java).
閱讀文章 →
Algorithms
cpp
更新於 2026-04-07
748.cpp
748.cpp — cpp source code from the Algorithms learning materials (Algorithms/748.cpp).
閱讀文章 →
Algorithms
cpp
更新於 2026-04-07
827.cpp
827.cpp — cpp source code from the Algorithms learning materials (Algorithms/827.cpp).
閱讀文章 →
Algorithms
cpp
更新於 2026-04-07
827_best_greedy.cpp
827_best_greedy.cpp — cpp source code from the Algorithms learning materials (Algorithms/827_best_greedy.cpp).
閱讀文章 →
Algorithms
cpp
更新於 2026-04-07
8402.cpp
8402.cpp — cpp source code from the Algorithms learning materials (Algorithms/8402.cpp).
閱讀文章 →
Algorithms
cpp
更新於 2026-04-07
860.cpp
860.cpp — cpp source code from the Algorithms learning materials (Algorithms/860.cpp).
閱讀文章 →