Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370#39. 「NOIP2010」机器翻译ryp10024ms3488kbC++14983b2025-04-22 13:18:592025-04-22 13:19:01

answer

#include <iostream>
#include <deque>
#include <set>
using namespace std;

int main() {
    int M, N;
    cin >> M >> N;

    deque<int> memory; // 用于存储内存中的单词
    set<int> in_memory; // 用于快速判断单词是否在内存中
    int dict_lookups = 0; // 记录查词典的次数

    for (int i = 0; i < N; ++i) {
        int word;
        cin >> word;

        if (in_memory.find(word) == in_memory.end()) {
            // 单词不在内存中,需要查词典
            dict_lookups++;

            if (memory.size() == M) {
                // 内存已满,移除最早进入内存的单词
                int oldest_word = memory.front();
                memory.pop_front();
                in_memory.erase(oldest_word);
            }

            // 将新单词存入内存
            memory.push_back(word);
            in_memory.insert(word);
        }
    }

    cout << dict_lookups << endl;
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 2ms
memory: 3240kb

input:

1 5
714 714 714 714 430

output:

2

result:

ok "2"

Test #2:

score: 10
Accepted
time: 3ms
memory: 3356kb

input:

2 10
211 824 992 55 992 55 992 55 211 264

output:

6

result:

ok "6"

Test #3:

score: 10
Accepted
time: 1ms
memory: 3468kb

input:

5 50
107 56 739 56 107 97 97 107 111 130 421 56 111 391 312 107 111 739 295 391 421 800 756 459 94 9...

output:

39

result:

ok "39"

Test #4:

score: 10
Accepted
time: 3ms
memory: 3416kb

input:

10 100
206 687 145 687 206 206 994 145 687 145 651 206 145 159 651 412 651 412 145 336 427 368 321 9...

output:

79

result:

ok "79"

Test #5:

score: 10
Accepted
time: 1ms
memory: 3352kb

input:

50 100
56 56 237 912 808 180 56 503 272 535 34 808 180 871 237 237 535 34 845 56 272 272 503 729 845...

output:

50

result:

ok "50"

Test #6:

score: 10
Accepted
time: 1ms
memory: 3416kb

input:

50 200
380 740 70 81 380 464 380 150 380 464 773 821 464 821 821 874 712 993 551 551 427 278 654 445...

output:

105

result:

ok "105"

Test #7:

score: 10
Accepted
time: 4ms
memory: 3244kb

input:

50 500
785 965 151 151 151 151 783 151 140 858 858 858 993 757 965 314 831 304 957 858 858 314 783 1...

output:

356

result:

ok "356"

Test #8:

score: 10
Accepted
time: 3ms
memory: 3272kb

input:

70 500
157 157 157 526 998 852 814 533 157 998 580 164 998 182 182 431 533 182 537 812 526 685 812 3...

output:

307

result:

ok "307"

Test #9:

score: 10
Accepted
time: 2ms
memory: 3364kb

input:

100 500
363 91 14 37 668 668 210 285 436 436 37 91 91 363 627 652 735 210 989 585 331 735 819 285 62...

output:

297

result:

ok "297"

Test #10:

score: 10
Accepted
time: 4ms
memory: 3488kb

input:

100 1000
918 918 918 918 784 918 918 865 2 2 472 230 384 230 865 900 350 786 384 784 900 798 918 655...

output:

640

result:

ok "640"