Submission #48659252


Source Code Expand

Copy
#include<iostream>
#include<map>
#include<set>
#include<numeric>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef pair<int,P> PP;
const ll INF=1LL<<60;
const int inf=1<<30;
int main(){
int N,K;
cin>>N>>K;
vector<int> p(N);
for(int i=0;i<N;i++){
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include<iostream>
#include<map>
#include<set>
#include<numeric>
#include<vector>
#include<algorithm>
#include<queue>
#include<tuple>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef pair<int,P> PP;
const ll INF=1LL<<60;
const int inf=1<<30;


int main(){
    int N,K;
    cin>>N>>K;
    vector<int> p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }   

    /*
    seg木
    */


    //
    multiset<int> mst;
    //i=0,1,2,..,K-1
    for(int i=0;i<K;i++){
        mst.insert(p[i]);
    }   
    vector<int> ans;
    //mstの大きさがK

    ans.push_back(*mst.begin());//K番目に大きいので,最小

    for(int i=K;i<N;i++){
        
        int v=*mst.begin();
        if(p[i]>v){
            mst.erase(mst.find(v));
            mst.insert(p[i]);
        }
        ans.push_back(*mst.begin());
    }

    for(int v:ans){
        cout<<v<<endl;
    }


}

Submission Info

Submission Time
Task G - Prefix K-th Max
User HIcoder
Language C++ 20 (gcc 12.2)
Score 400
Code Size 952 Byte
Status AC
Exec Time 549 ms
Memory 28540 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 28
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 3488 KB
001.txt AC 541 ms 7904 KB
002.txt AC 230 ms 28540 KB
003.txt AC 432 ms 17896 KB
004.txt AC 478 ms 15188 KB
005.txt AC 431 ms 15964 KB
006.txt AC 276 ms 5176 KB
007.txt AC 516 ms 9788 KB
008.txt AC 166 ms 9608 KB
009.txt AC 204 ms 7620 KB
010.txt AC 549 ms 7776 KB
011.txt AC 539 ms 7904 KB
012.txt AC 187 ms 28512 KB
013.txt AC 178 ms 28420 KB
014.txt AC 410 ms 17908 KB
015.txt AC 355 ms 17852 KB
016.txt AC 407 ms 17924 KB
017.txt AC 359 ms 18068 KB
018.txt AC 542 ms 7892 KB
019.txt AC 546 ms 7936 KB
020.txt AC 160 ms 28540 KB
021.txt AC 188 ms 28444 KB
022.txt AC 392 ms 17856 KB
023.txt AC 389 ms 17760 KB
024.txt AC 394 ms 17900 KB
025.txt AC 389 ms 17900 KB
example0.txt AC 1 ms 3500 KB
example1.txt AC 1 ms 3696 KB


2025-04-09 (Wed)
14:29:10 +00:00