QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#368184#1173. Knowledge Is...GraphcityWA 1ms6120kbC++201.1kb2024-03-26 21:40:562024-03-26 21:40:56

Judging History

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

  • [2024-03-26 21:40:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6120kb
  • [2024-03-26 21:40:56]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=3e5;

int n,m,s,mch[Maxn+5],ans[Maxn+5];
struct Data{int k,a,b;}; array<int,3> h[Maxn+5];
inline bool operator<(Data x,Data y) {return x.k>y.k;}

int main()
{
    // freopen("1.in","r",stdin);

    cin>>n>>m;
    For(i,1,n) cin>>h[i][0]>>h[i][1],h[i][2]=i;
    sort(h+1,h+n+1); priority_queue<Data> q1,q2;
    For(_,1,n)
    {
        auto [l,r,id]=h[_];
        if(!q1.empty() && q1.top().k<l)
        {
            int p=q1.top().a; q1.pop();
            mch[p]=id,mch[id]=p,q2.push(Data{r,p,id});
        }
        else if(!q2.empty() && q2.top().k<l)
        {
            auto [k,a,b]=q2.top(); q2.pop();
            mch[a]=id,mch[id]=a,mch[b]=0;
            q2.push(Data{r,a,id}),q1.push(Data{k,b,0});
        } else q1.push(Data{r,id,0});
    }
    For(i,1,n) if(mch[i] && !ans[i] && s<m) ++s,ans[i]=ans[mch[i]]=s;
    For(i,1,n) if(!ans[i] && s<m) ans[i]=++s;
    For(i,1,n) printf("%d ",ans[i]); printf("\n");
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 6120kb

input:

7 5
9 10
7 9
3 4
9 10
2 6
8 9
5 8

output:

1 2 1 3 2 4 3 

result:

ok answer = 7

Test #2:

score: 0
Accepted
time: 1ms
memory: 5824kb

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

score: 0
Accepted
time: 0ms
memory: 4080kb

input:

2 1
1 2
2 3

output:

1 0 

result:

ok answer = 1

Test #4:

score: 0
Accepted
time: 0ms
memory: 3716kb

input:

1 1
4 26

output:

1 

result:

ok answer = 1

Test #5:

score: 0
Accepted
time: 0ms
memory: 6068kb

input:

500 258
1 3
3 5
2 4
3 5
4 5
4 5
1 4
1 2
3 5
2 5
2 5
4 5
4 5
4 5
2 3
1 4
1 4
1 4
4 5
4 5
2 3
4 5
3 5
3 5
1 5
1 4
2 5
1 5
3 5
3 4
4 5
2 3
3 5
3 5
4 5
2 3
1 5
1 5
2 3
2 3
3 4
3 5
3 4
1 3
1 2
1 5
4 5
2 3
2 4
1 3
4 5
4 5
4 5
1 3
3 5
4 5
3 5
1 5
1 2
1 2
3 5
3 5
4 5
3 4
3 5
2 3
2 5
2 4
2 5
3 5
2 3
1 5
4 5
...

output:

1 119 120 121 2 3 122 4 123 124 125 5 6 7 8 126 127 128 9 10 11 12 129 130 131 132 133 134 135 4 13 14 136 137 15 16 138 139 17 18 19 140 20 21 22 141 23 24 142 25 26 27 28 29 143 30 144 145 19 31 146 147 32 33 148 34 149 150 151 152 35 153 36 154 155 37 38 39 156 40 41 157 42 43 20 44 158 45 46 47 ...

result:

ok answer = 376

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 5804kb

input:

500 242
8 9
9 10
2 9
8 10
9 10
6 10
4 8
4 5
2 6
7 10
3 8
1 8
1 6
5 9
7 8
8 10
8 9
8 10
2 9
2 3
6 8
3 10
5 9
1 3
6 8
4 10
9 10
8 9
8 10
1 9
3 9
3 7
2 3
6 10
3 6
6 10
3 4
3 6
9 10
5 7
8 10
6 10
5 6
5 7
7 8
1 3
4 7
9 10
4 9
2 4
8 9
1 3
8 10
3 4
9 10
4 9
5 10
8 9
1 3
1 5
8 10
3 4
8 9
3 9
3 6
3 10
6 7
7 ...

output:

1 2 201 3 4 202 5 6 7 8 9 10 11 12 13 14 15 16 203 17 18 204 19 20 21 205 22 23 24 206 207 25 26 208 27 209 28 13 29 30 31 210 32 31 33 34 35 36 211 37 38 39 40 12 41 212 213 42 43 44 30 45 46 214 47 215 48 49 216 50 51 52 217 53 54 55 56 57 42 218 58 59 60 4 61 62 63 64 219 220 65 66 55 221 67 222 ...

result:

wrong answer participant answer = 442, judge answer = 471