QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#867649#8889. Ice Cream MachinesKK1729#7 1ms3840kbC++172.0kb2025-01-23 20:58:072025-01-23 20:58:08

Judging History

你现在查看的是最新测评结果

  • [2025-01-23 20:58:08]
  • 评测
  • 测评结果:7
  • 用时:1ms
  • 内存:3840kb
  • [2025-01-23 20:58:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long 
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(a) a.begin(), a.end()
#define endl "\n"

void printVector(vector<int> a){
    for (auto x: a) cout << x << " ";
    cout << endl;
}

void solve(){
    int n, m, k; cin >> n >> m >> k;



    vector<int> c(n);
    FOR(i,0,n) cin >> c[i];

    vector<int> pos(m+1);
    vector<vector<int>> e(m+1);
    FOR(i,0,n) e[c[i]].pb(i);
    FOR(i,0,n) pos[c[i]] = i;
    // cout << endl;
    vector<int> nex(n, 1e9);
    FOR(i,1,m+1){
        // printVector(e[i]);
        FOR(j,0,e[i].size()-1){
            nex[e[i][j]] = e[i][j+1];
        }
    }
    // cout << endl;
    int avail = k;
    // int l = 0;
    set<int> s;
    set<pair<int, int>> o;
    vector<int> active(m+1);
    int ans = 0;
    // nex[0] = 4;
    // printVector(nex);

    vector<int> prev(m+1, -1);
    FOR(i,0,n){
        if (active[c[i]]){
            int t = prev[c[i]];
            if (t > 1e6) continue;
            auto x = o.find({-t, c[i]});
            if (x == o.end()) continue;
            o.erase(x);
            o.insert({-(nex[i]), c[i]});
        }else{
            ans++;
            if (avail == 0){
                
                auto u = *o.begin();
                int x = u.second;    
                                
                
                o.erase(o.find(u));
                active[x] = 0;
                active[c[i]] = 1;
                o.insert({-nex[i], c[i]});
                prev[c[i]] = nex[i];
            }else{
                avail--;
                o.insert({-nex[i], c[i]});
                active[c[i]] = 1;
                prev[c[i]] = nex[i];
            }
        }
        // cout << i << ans << endl;
    }
    cout << ans << endl;
}


int32_t main(){
    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int t = 1; // cin >> t;
    while (t--) solve();
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 7
Accepted

Test #1:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

1000 10 1
3
6
6
8
4
7
4
10
1
6
6
2
1
8
4
10
5
9
3
4
7
5
9
6
2
8
8
7
1
1
1
9
8
6
4
6
5
4
8
8
2
3
1
7
7
10
4
10
5
5
2
7
5
1
6
8
7
9
10
4
9
2
4
5
7
8
10
9
1
5
1
7
10
4
10
10
5
10
10
10
5
3
5
5
7
4
6
6
10
6
9
5
6
3
3
3
7
10
7
4
5
10
6
4
2
4
8
7
6
9
7
5
6
9
9
7
4
5
8
8
10
6
1
4
9
3
9
10
1
7
3
4
8
1
3
9
5...

output:

899

result:

ok 1 number(s): "899"

Test #2:

score: 7
Accepted
time: 1ms
memory: 3712kb

input:

1000 1 1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1...

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

751 8 1
8
6
5
4
7
8
2
6
4
7
4
2
2
5
3
7
7
3
7
2
5
3
4
8
6
8
1
4
3
8
4
1
3
3
5
3
6
6
8
8
1
4
6
8
8
3
5
7
5
7
1
1
1
2
8
1
8
6
4
5
1
2
7
5
5
5
7
4
3
1
4
3
8
6
5
3
1
7
5
7
8
3
8
2
6
8
6
5
4
1
1
5
1
4
7
7
5
2
6
8
4
3
2
6
5
7
7
4
4
5
1
7
2
2
2
6
7
6
2
4
7
3
2
6
2
3
2
1
4
8
8
7
6
3
4
7
2
4
3
1
7
2
7
1
3
6
...

output:

655

result:

ok 1 number(s): "655"

Test #4:

score: 7
Accepted
time: 0ms
memory: 3840kb

input:

857 3 1
1
3
1
3
2
1
1
2
2
2
1
3
3
3
2
2
3
1
3
1
1
3
1
3
3
2
1
3
1
3
1
1
3
2
2
1
1
3
1
1
2
3
1
1
2
1
3
3
3
3
3
1
1
2
2
3
1
1
2
2
2
3
2
1
2
2
2
3
2
1
3
3
2
2
1
2
3
1
1
1
3
2
3
3
3
1
3
2
2
2
1
3
3
3
2
2
3
1
1
1
1
3
1
3
3
3
1
2
1
3
1
3
2
3
3
3
1
1
1
3
1
3
3
2
2
1
3
3
1
1
3
1
2
1
1
1
2
1
2
2
3
2
2
2
2
3
...

output:

565

result:

ok 1 number(s): "565"

Test #5:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

888 3 1
2
1
1
3
2
3
2
2
2
1
2
2
1
3
2
1
1
1
2
3
3
1
2
3
1
3
3
3
2
2
1
2
2
1
1
1
2
2
1
3
1
3
3
3
3
2
2
1
3
3
1
1
1
3
3
2
1
2
3
3
2
2
1
3
3
2
1
1
1
1
1
2
2
2
2
3
3
2
1
1
2
3
2
2
1
3
3
1
2
1
2
1
1
2
1
2
1
3
2
2
3
1
3
3
1
1
1
3
1
2
3
2
1
1
1
2
3
2
2
1
2
1
3
3
3
2
3
1
2
2
3
1
1
3
3
3
2
3
2
1
1
3
1
2
3
1
...

output:

599

result:

ok 1 number(s): "599"

Test #6:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

998 4 1
2
4
1
1
3
4
3
3
2
2
1
2
3
3
4
4
3
3
1
1
1
4
2
1
2
2
2
2
3
2
2
1
2
2
4
3
3
3
3
2
2
3
3
2
3
4
3
4
3
2
4
2
1
2
3
3
2
3
2
4
1
4
1
4
1
4
1
2
3
1
4
3
1
2
2
3
3
2
1
3
3
3
4
2
1
3
2
3
3
4
3
4
1
4
3
4
3
3
1
4
2
3
2
1
4
2
1
1
4
3
4
2
4
4
3
4
4
1
3
4
4
1
2
3
2
1
1
3
3
1
3
3
4
3
1
3
2
4
1
4
4
2
4
2
2
4
...

output:

731

result:

ok 1 number(s): "731"

Test #7:

score: 7
Accepted
time: 1ms
memory: 3840kb

input:

1000 10 1
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9
10
1
2
3
4
5
6
7
8
9...

output:

1000

result:

ok 1 number(s): "1000"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #8:

score: 0
Wrong Answer
time: 0ms
memory: 3840kb

input:

1000 10 2
5
1
5
10
1
10
9
10
3
9
7
6
4
3
1
10
7
9
5
9
5
4
2
7
7
8
4
4
4
3
10
8
4
2
5
7
5
10
9
2
6
1
4
7
9
5
6
3
4
3
5
4
3
9
2
6
3
2
6
9
8
4
5
5
2
9
10
2
6
1
7
3
6
6
7
4
10
7
8
5
8
8
2
7
8
10
5
2
8
4
2
10
3
9
7
8
6
7
9
7
9
2
5
4
5
10
2
4
3
9
2
3
7
9
3
10
8
4
1
8
9
10
8
10
2
6
3
2
2
5
5
2
8
7
9
5
7
7
...

output:

793

result:

wrong answer 1st numbers differ - expected: '629', found: '793'

Subtask #3:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%