QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#335159#7942. $K$ SubsequencesnicnaknicWA 1ms3596kbC++172.0kb2024-02-22 20:27:482024-02-22 20:27:48

Judging History

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

  • [2024-02-22 20:27:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3596kb
  • [2024-02-22 20:27:48]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <set>

using namespace std;
typedef long long LL;
#define int LL
const int N = 2e5+10,P = N*10*10,M = N*2,mod = 1e9+7,INF = 1e9;
#define x first
#define y second
typedef pair<int,int> PII;
int n,k;
int a[N];
int last[N];
int b[N];
priority_queue<PII> heap_max;
priority_queue<PII,vector<PII>,greater<PII>>heap_min;
signed main()
{
   ios::sync_with_stdio(false);
   cin.tie(NULL); cout.tie(NULL);
    int T;
    cin>>T;
    while(T--)
    {
       cin>>n>>k;
       for(int i = 1;i<=n;i++) cin>>a[i];
        while(heap_max.size()) heap_max.pop();
        while(heap_min.size()) heap_min.pop();
        for(int i = 1;i<=k;i++)
        {
          heap_max.push({0,i});
          heap_min.push({0,i});
          last[i] = 0;
        }
        for(int i = 1;i<=n;i++)
        {
            if(a[i]==1)
            {
              PII t;
              while(heap_min.size())
              {
               t = heap_min.top();
                heap_min.pop();
                if(last[t.y]==t.x) break;
              }
              int pos = t.second,x = t.first;
              last[pos]++;
              b[i]  = pos;
              heap_min.push({last[pos],pos});
              heap_max.push({last[pos],pos});
            }
            else
            {
               PII t;
               while(heap_max.size())
               {
                 t = heap_max.top();
                 heap_max.pop();
                 if(last[t.y]==t.x) break;
               }
              int pos = t.second,x = t.first;
              last[pos]=0;
              b[i]  = pos;
              heap_min.push({last[pos],pos});
              heap_max.push({last[pos],pos});
            }
        }
       for(int i = 1;i<=n;i++)
          cout<<b[i]<<" ";
        cout<<endl;
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3596kb

input:

5
3 2
1 -1 1
4 2
-1 1 1 -1
7 3
1 1 1 1 1 1 1
10 3
1 1 1 1 -1 -1 1 1 1 1
12 4
1 1 1 1 -1 -1 -1 -1 1 1 1 1

output:

1 1 1 
2 1 2 2 
1 2 3 1 2 3 1 
1 2 3 1 1 3 1 3 1 2 
1 2 3 4 4 3 2 1 1 2 3 4 

result:

wrong answer Jury found better answer than participant (test case 4)