QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282143#1173. Knowledge Is...SoyTonyWA 1ms5904kbC++141.7kb2023-12-11 14:30:242023-12-11 14:30:24

Judging History

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

  • [2023-12-11 14:30:24]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5904kb
  • [2023-12-11 14:30:24]
  • 提交

answer

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

typedef pair<int,int> pii;
#define fir first
#define sec second
const int maxn=3e5+10;
const int inf=0x3f3f3f3f;

inline int read(){
    int x=0,w=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')w=-1;c=getchar();}
    while(c<='9'&&c>='0'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return x*w;
}

int n,m;
map<pii,int> mp;
pii p[maxn];
struct Pair{
    pii A,B;
    Pair()=default;
    Pair(pii A_,pii B_):A(A_),B(B_){}
    bool operator<(const Pair &rhs)const{
        return B.sec>rhs.B.sec;
    }
};
priority_queue<Pair> Q1,Q2;
int ans[maxn];

int main(){
    // freopen("interval.in","r",stdin);
    // freopen("interval.out","w",stdout);
    n=read(),m=read();
    for(int i=1;i<=n;++i){
        p[i].fir=read(),p[i].sec=read();
        mp[p[i]]=i;
    }
    sort(p+1,p+n+1);
    for(int i=1;i<=n;++i){
        if(!Q1.empty()&&Q1.top().B.sec<p[i].fir){
            Pair now=Q1.top();
            Q1.pop();
            Q2.push(Pair(now.B,p[i]));
        }
        else{
            if(!Q2.empty()&&Q2.top().B.sec<p[i].sec){
                Pair now=Q2.top();
                Q2.pop();
                Q1.push(Pair(make_pair(0,0),now.B));
                now.B=p[i];
                Q2.push(now);
            }
            else Q1.push(Pair(make_pair(0,0),p[i]));
        }
    }
    for(int i=1,j=1;i<=m;++i){
        if(!Q2.empty()){
            Pair now=Q2.top();
            Q2.pop();
            ans[mp[now.A]]=i,ans[mp[now.B]]=i;
        }
        else{
            while(j<=n&&ans[j]) ++j;
            if(j<=n) ans[j]=i;
        }
    }
    for(int i=1;i<=n;++i) printf("%d ",ans[i]);
    printf("\n");
    return 0;
}

详细

Test #1:

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

input:

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

output:

4 5 1 3 3 1 2 

result:

ok answer = 7

Test #2:

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

input:

2 2
1 2
3 4

output:

1 1 

result:

ok answer = 2

Test #3:

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

input:

2 1
1 2
2 3

output:

1 0 

result:

ok answer = 1

Test #4:

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

input:

1 1
4 26

output:

1 

result:

ok answer = 1

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 5900kb

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:

119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 ...

result:

wrong answer participant answer = 145, judge answer = 376