QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#105898 | #4887. Fast Bridges | 1kri | WA | 8ms | 4212kb | C++14 | 2.9kb | 2023-05-15 21:09:15 | 2023-05-15 21:09:16 |
Judging History
answer
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
#define mod 998244353
using namespace std;
int tot,V;
int S,ans;
struct WORK{
int tot,xa[505],ya[505],xb[505],yb[505];
int n,m,pos_x[1005],pos_y[1005];
map<int,int> id_x,id_y;
int dis[505][505];
int id[505];
int f[505],h[505];
void bubble_sort1(){
for (int i=1;i<=tot;i++)
for (int j=1;j<tot;j++)
if (ya[j]>ya[j+1]){
swap(xa[j],xa[j+1]);
swap(ya[j],ya[j+1]);
swap(xb[j],xb[j+1]);
swap(yb[j],yb[j+1]);
}
return;
}
void bubble_sort2(){
for (int i=1;i<=tot;i++)
for (int j=1;j<tot;j++)
if (yb[id[j]]>yb[id[j+1]])swap(id[j],id[j+1]);
return;
}
void work(){
id_x[V]=1,pos_x[++n]=V;
id_y[V]=1,pos_y[++m]=V;
for (int i=1;i<=tot;i++){
if (id_x[xa[i]]==0){
id_x[xa[i]]=1;
pos_x[++n]=xa[i];
}
if (id_y[ya[i]]==0){
id_y[ya[i]]=1;
pos_y[++m]=ya[i];
}
if (id_x[xb[i]-1]==0){
id_x[xb[i]-1]=1;
pos_x[++n]=xb[i]-1;
}
if (id_y[yb[i]-1]==0){
id_y[yb[i]-1]=1;
pos_y[++m]=yb[i]-1;
}
}
sort(pos_x+1,pos_x+1+n);
for (int i=1;i<=n;i++)id_x[pos_x[i]]=i;
sort(pos_y+1,pos_y+1+m);
for (int i=1;i<=m;i++)id_y[pos_y[i]]=i;
for (int i=1;i<=tot;i++){
xa[i]=id_x[xa[i]];
ya[i]=id_y[ya[i]];
xb[i]=id_x[xb[i]-1]+1;
yb[i]=id_y[yb[i]-1]+1;
}
bubble_sort1();
for (int i=1;i<=tot;i++)
for (int j=i+1;j<=tot;j++)
if (xb[i]<=xa[j]&&yb[i]<=ya[j])dis[i][j]=1;
for (int k=1;k<=tot;k++)
for (int i=1;i<k;i++)
for (int j=k+1;j<=tot;j++)
if (dis[i][k]>0&&dis[k][j]>0)dis[i][j]=max(dis[i][j],dis[i][k]+dis[k][j]);
for (int i=1;i<=tot;i++)id[i]=i;
bubble_sort2();
for (int i=n;i>=1;i--){
memset(f,0,sizeof(f));
int p=tot;
for (int j=m;j>=1;j--){
while(p>=1&&ya[p]>=j){
if (xa[p]>=i){
f[p]=1;
for (int k=p+1;k<=tot;k++)
if (xa[k]>=i&&dis[p][k]>0)f[k]=max(f[k],dis[p][k]+1);
}
p--;
}
for (int k=1;k<=tot;k++)h[k]=V+1;
int s=0;
for (int k=1;k<=tot;k++){
int t=id[k];
if (f[t]>0){
int _f=f[t],_x=xb[t],_y=yb[t];
if (pos_x[_x]<h[_f]){
s=(s+1ll*(h[_f]-(pos_x[_x-1]+1))*(V-(pos_y[_y-1]+1)+1))%mod;
h[_f]=pos_x[_x-1]+1;
}
}
}
ans=(ans+1ll*(pos_x[i]-pos_x[i-1])*(pos_y[i]-pos_y[i-1])%mod*s)%mod;
}
}
return;
}
}work1,work2;
int main(){
cin>>tot>>V;
S=(1ll*V*(V+1)/2%mod*(-V-1)%mod+mod)%mod;
S=(S+1ll*V*(V+1)%mod*(2*V+1)%mod*((mod+1)/3)%mod)%mod;
S=1ll*S*V%mod*V%mod*2%mod;
for (int i=1;i<=tot;i++){
int xa,ya,xb,yb;
cin>>xa>>ya>>xb>>yb;
if (ya<yb){
int t=++work1.tot;
work1.xa[t]=xa,work1.ya[t]=ya,work1.xb[t]=xb,work1.yb[t]=yb;
}
else{
int t=++work2.tot;
work2.xa[t]=xa,work2.ya[t]=V-ya+1,work2.xb[t]=xb,work2.yb[t]=V-yb+1;
}
}
work1.work();
work2.work();
cout<<(S-ans+mod)%mod<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 3464kb
input:
2 2 1 1 2 2 1 2 2 1
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3316kb
input:
0 1000000000
output:
916520226
result:
ok answer is '916520226'
Test #3:
score: 0
Accepted
time: 2ms
memory: 3432kb
input:
5 5 1 1 3 3 3 3 5 1 3 3 4 5 3 3 5 4 1 5 3 3
output:
946
result:
ok answer is '946'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3684kb
input:
200 5 1 1 4 2 2 5 4 4 2 3 4 2 2 4 3 5 1 4 4 2 2 5 4 2 1 2 4 4 1 2 2 4 1 4 5 1 3 4 5 1 4 2 5 1 2 2 5 4 3 2 5 1 3 1 5 2 4 2 5 3 1 3 5 1 3 4 4 5 2 2 4 3 2 3 5 4 1 4 5 3 2 2 3 1 2 5 3 3 1 1 5 3 4 4 5 5 1 3 4 4 4 3 5 1 2 3 3 4 3 4 4 2 1 4 4 5 2 1 4 4 1 3 5 2 1 1 3 3 1 5 3 1 1 1 3 5 1 4 3 5 4 5 5 4 1 1 4 ...
output:
708
result:
ok answer is '708'
Test #5:
score: 0
Accepted
time: 4ms
memory: 4116kb
input:
500 10 5 6 7 10 1 3 8 10 3 3 4 9 2 10 10 2 9 4 10 10 5 4 7 8 7 1 10 7 3 1 7 10 5 2 8 9 6 3 7 10 3 10 7 9 4 9 5 1 2 5 3 3 7 10 8 2 7 7 9 8 6 6 8 3 5 10 8 8 1 1 5 5 3 3 10 5 5 5 7 6 3 8 4 7 6 7 7 5 7 3 10 9 5 3 9 4 4 6 10 5 1 5 9 10 5 6 9 7 3 10 10 3 1 2 5 7 4 6 5 1 3 1 8 5 5 8 8 9 1 8 4 3 6 4 7 10 7 ...
output:
27373
result:
ok answer is '27373'
Test #6:
score: 0
Accepted
time: 4ms
memory: 4212kb
input:
500 30 3 13 20 29 14 5 16 25 2 29 9 15 23 30 24 9 1 18 24 28 4 16 5 2 3 29 30 25 4 8 24 19 8 26 10 24 20 14 26 25 15 8 25 25 5 13 18 28 3 30 29 10 14 26 25 11 11 19 16 4 9 4 29 30 15 10 16 8 2 29 12 2 11 22 20 28 4 10 28 1 24 17 30 1 8 26 27 9 15 25 30 14 16 20 24 17 9 23 12 13 9 16 25 28 2 15 8 16 ...
output:
7717993
result:
ok answer is '7717993'
Test #7:
score: -100
Wrong Answer
time: 8ms
memory: 4140kb
input:
500 100 25 55 55 43 14 22 84 5 57 7 79 15 63 9 86 23 22 3 53 97 2 22 64 65 32 52 66 30 76 37 79 22 46 100 76 22 21 78 78 44 29 41 92 55 43 14 46 3 14 97 42 1 16 7 35 64 15 27 29 3 11 92 92 70 4 13 66 2 3 38 55 82 41 94 83 44 52 90 100 82 6 100 99 70 18 38 24 22 74 17 98 20 17 94 44 82 33 97 48 19 12...
output:
291620873
result:
wrong answer expected '291628571', found '291620873'