QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#630271 | #5143. Quick Sort | 999# | WA | 1ms | 5964kb | C++14 | 1.6kb | 2024-10-11 17:26:29 | 2024-10-11 17:26:36 |
Judging History
answer
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
#define CC(_...) fprintf(stderr,_)
using namespace std;
typedef long long LL;
const int N=200007;
int n,e,ml,sr,L[N],R[N],E[N],D[N],W[N],F[N];
void magic() {
scanf("%d",&n);
e=sr=0;
For(i,1,n) {
scanf("%d%d",&L[i],&R[i]);
E[++e]=R[i],E[++e]=L[i]-1;
}
if(n==1) {
puts("1");
return;
}
sort(E+1,E+1+e),e=unique(E+1,E+1+e)-E-1;
For(i,1,e) D[i]=W[i]=F[i]=0;
F[e]=E[e];
For(i,1,n) {
int l=lower_bound(E+1,E+1+e,L[i]-1)-E;
int r=lower_bound(E+1,E+1+e,R[i])-E;
if(r==E[e]) ml=L[i];
else sr=max(sr,R[i]);
D[l+1]++,D[r+1]--,W[r]++;
F[l]=L[i]-1;
}
if(W[e]>1) sr=E[e];
Dor(i,e,1) if(!F[i]) F[i]=F[i+1];
LL ans=0;
int p=0;
For(i,2,e) {
D[i]+=D[i-1];
if(!D[i]) {
if(p>=2&&p<=n-2) {
ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
}
else if(p==1&&n>=3) {
int c=0,l=E[e];
For(j,1,n) {
if(L[j]>E[i]) {
l=min(l,L[j]);
++c;
}
}
if(c>=3) ans+=1LL*(E[i]-E[i-1])*(E[e]-l);
else {
int s=0,d=D[i];
For(j,i+1,e) if(d+=D[j]) s+=E[j]-E[j-1];
ans+=1LL*(E[i]-E[i-1])*s;
}
}
}
else {
if(D[i]>1||p&&i!=e) {
ans+=1LL*(E[i]-E[i-1])*(E[i]-E[i-1]-1)/2;
ans+=1LL*(E[i]-E[i-1])*(E[e]-E[i]);
}
else {
int r=E[e];
if(D[i]==1&&ml<=E[i]) {
r=sr;
}
ans+=1LL*(E[i]-E[i-1])*max(0,r-F[i]);
}
}
p+=W[i];
}
printf("%lld\n",ans);
}
int main() {
int T; scanf("%d",&T);
while(T--) magic();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5964kb
input:
3 3 3 2 1 5 2 4 5 3 1 10 7 2 4 6 1 9 10 8 5 3
output:
9 20 54
result:
wrong answer 1st numbers differ - expected: '1', found: '9'