QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#359490 | #5558. Formula Flatland | crsfaa# | WA | 98ms | 96224kb | C++14 | 3.1kb | 2024-03-20 18:33:16 | 2024-03-20 18:33:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int read() {
int q=0,w=1;char ch=' ';
while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
if(ch=='-') w=-1,ch=getchar();
while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
return q*w;
}
typedef long long LL;
typedef double db;
const int N=600005,M=1200005;const db eps=1e-10;
#define RI register int
int n,m,Q,tot=1,cnt,rt;LL ans1,ans2;
struct point{int x,y;}p[N];
point operator - (point a,point b) {return (point){a.x-b.x,a.y-b.y};}
LL operator * (point a,point b) {return 1LL*a.x*b.y-1LL*a.y*b.x;}
struct edge{int id,u,v;db jd;}e[M];
bool operator < (edge a,edge b) {return fabs(a.jd-b.jd)<eps?a.v<b.v:a.jd<b.jd;}
int nxt[M],pos[M],f[M],vis[M],istr[M],ask[M];LL s[M],ss[M];
vector<edge> h[N],tr[M];
void link(int x,int y) {
++tot,e[tot]=(edge){tot,x,y,atan2(p[y].y-p[x].y,p[y].x-p[x].x)};
h[x].push_back(e[tot]);
}
void build() {
for(RI i=1;i<=n;++i) sort(h[i].begin(),h[i].end());
for(RI i=2;i<=tot;++i) {
int v=e[i].v;
vector<edge>::iterator kl=lower_bound(h[v].begin(),h[v].end(),e[i^1]);
if(kl==h[v].begin()) kl=h[v].end();//其前一条就是最后一条
--kl,nxt[i]=(*kl).id;
}
for(RI i=2;i<=tot;++i) {
if(pos[i]) continue;
pos[i]=pos[nxt[i]]=++cnt;
for(RI j=nxt[i];e[j].v!=e[i].u;j=nxt[j],pos[j]=cnt)
s[cnt]+=(p[e[j].u]-p[e[i].u])*(p[e[j].v]-p[e[i].u]);//计算面积
if(s[cnt]<=0) rt=cnt;//无穷域
}
for(RI i=2;i<=tot;++i) tr[pos[i]].push_back((edge){i,pos[i],pos[i^1]});
int mn=2e9;
for(int i=0;i<=6e5;i++)
if(tr[i].size())
mn=min(mn,(int)tr[i].size());
cout<<mn;
exit(0);
}
void dfs(int x,int las) {//生成树
f[x]=las,ss[x]=1LL*s[x]*s[x],s[x]<<=1,vis[x]=1;
//叉积算面积后应该除以2,但是为了避免小数,所以分子分母同时乘4
for(RI i=0,sz=tr[x].size();i<sz;++i) {
int v=tr[x][i].v;
if(vis[v]) continue;
istr[tr[x][i].id]=istr[tr[x][i].id^1]=1,dfs(v,x);
s[x]+=s[v],ss[x]+=ss[v];
}
}
LL gcd(LL a,LL b) {return b?gcd(b,a%b):a;}
void work() {
while(Q--) {
int js=(read()+ans1)%n+1;
for(RI i=1;i<=js;++i) ask[i]=(read()+ans1)%n+1;
ask[js+1]=ask[1],ans1=ans2=0;
for(RI i=1;i<=js;++i) {
int x=ask[i],y=ask[i+1];
edge ke=(edge){0,x,y,atan2(p[y].y-p[x].y,p[y].x-p[x].x)};
vector<edge>::iterator kl=lower_bound(h[x].begin(),h[x].end(),ke);//找边
int j=(*kl).id;
if(!istr[j]) continue;//该边所在区域,是儿子就加是父亲就减
if(f[pos[j]]==pos[j^1]) ans1+=ss[pos[j]],ans2+=s[pos[j]];
else ans1-=ss[pos[j^1]],ans2-=s[pos[j^1]];
}
LL tmp=gcd(ans1,ans2);
ans1/=tmp,ans2/=tmp;
printf("%lld %lld\n",ans1,ans2);
}
}
int main()
{
int x,y;
n=read(),m=read(),Q=0;
for(RI i=1;i<=n;++i) p[i]=(point){read(),read()};
for(RI i=1;i<=m;++i) x=read(),y=read(),link(x,y),link(y,x);
build(),dfs(rt,0),work();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 54208kb
input:
4 6 0 0 3 0 0 3 1 1 1 2 1 3 1 4 2 3 2 4 3 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 4ms
memory: 53368kb
input:
10 15 1 5 2 1 3 4 4 2 5 3 6 2 7 3 8 1 9 4 11 5 1 2 1 3 1 10 2 4 3 5 4 5 4 6 5 7 6 7 6 8 7 9 8 10 9 10 2 8 3 9
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 3ms
memory: 52540kb
input:
12 18 0 0 10 10 20 0 15 1 15 4 17 2 13 2 8 7 5 3 8 5 8 6 7 4 1 3 1 4 1 7 2 3 2 5 2 8 3 6 4 5 4 6 5 6 7 9 7 10 8 9 8 11 9 12 10 11 10 12 11 12
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 8ms
memory: 52948kb
input:
8 12 0 0 12 0 3 2 6 6 6 1 9 2 6 5 6 4 1 2 1 3 1 5 2 4 2 6 3 4 3 8 4 7 5 6 5 8 6 7 7 8
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 4ms
memory: 53880kb
input:
20 30 0 0 36 0 18 18 5 4 8 3 16 1 20 2 32 3 27 5 29 6 18 17 17 15 15 10 10 2 16 4 20 7 25 4 23 9 19 13 19 8 1 2 2 3 3 4 4 5 5 1 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 6 16 17 17 18 18 19 19 20 20 16 1 6 2 8 3 10 4 12 5 14 7 16 9 17 11 18 13 19 15 20
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 4ms
memory: 54304kb
input:
12 30 0 0 20 0 10 10 4 3 7 2 9 1 16 3 10 9 10 8 9 4 13 2 12 6 1 2 1 3 1 4 1 5 1 6 2 3 3 4 4 5 5 6 6 2 7 2 7 3 8 3 8 4 9 4 9 5 10 5 10 6 11 6 11 2 7 8 8 9 9 10 10 11 11 7 12 7 12 8 12 9 12 10 12 11
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 8ms
memory: 52736kb
input:
6 12 0 0 8 0 5 2 4 3 3 1 4 4 1 2 2 3 3 4 4 1 5 1 6 1 5 2 6 2 5 3 6 3 5 4 6 4
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 4ms
memory: 52968kb
input:
12 18 0 0 20 0 3 2 10 10 5 1 17 2 5 4 6 5 13 6 10 9 9 7 10 8 1 2 1 3 1 5 2 4 2 6 3 4 3 7 4 8 5 6 5 7 6 8 7 8 9 10 9 11 9 12 10 11 10 12 11 12
output:
3
result:
ok single line: '3'
Test #9:
score: 0
Accepted
time: 8ms
memory: 54112kb
input:
12 19 0 0 20 0 10 9 10 10 9 7 8 5 11 8 13 6 11 1 8 4 6 2 8 3 1 2 1 3 1 5 2 4 2 6 3 4 3 7 4 8 5 6 5 7 6 8 7 8 9 10 9 11 9 12 10 11 10 12 11 12 1 9
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 8ms
memory: 53404kb
input:
46 69 0 0 46 2 88 0 49 1 30 4 25 3 44 44 79 8 59 2 50 5 31 6 44 43 55 3 36 5 30 10 23 4 9 8 44 42 72 7 64 3 59 5 53 9 34 7 27 8 12 10 77 9 63 7 55 8 39 6 32 12 32 13 17 7 14 9 45 40 66 4 60 13 58 11 41 7 32 16 21 5 19 6 47 37 71 6 69 5 59 15 45 32 1 3 1 4 1 2 2 5 2 6 3 7 3 8 4 9 4 10 5 11 11 6 7 12 ...
output:
4
result:
ok single line: '4'
Test #11:
score: 0
Accepted
time: 86ms
memory: 91280kb
input:
99994 166652 0 0 164087 24231 16153 1467 80696 7356 55659 5065 130637 4863 178682 544 100912 7558 74630 6795 170587 16557 157941 2412 175028 11309 67128 6109 124070 5465 128321 5070 163029 1979 162531 1996 51885 4712 149664 41288 142160 3814 55444 5040 79209 7222 178706 6943 82464 7501 104751 7227 1...
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 98ms
memory: 91212kb
input:
99998 166660 0 0 44650 3765 182247 1495 112004 7385 139279 5119 58545 4895 6434 559 91137 7618 118668 6882 30458 2586 29030 2439 20799 1760 126793 6136 65967 5522 61316 5126 23468 1978 24029 2025 143489 4824 76139 6388 46024 3857 139549 5088 113899 7579 12750 1125 110075 7551 87058 7284 116307 7127 ...
output:
5
result:
ok single line: '5'
Test #13:
score: 0
Accepted
time: 96ms
memory: 88608kb
input:
99857 199084 0 0 133841 27313 130867 61811 35938 31076 137395 7465 148228 50647 58797 16554 156910 20181 20200 12984 135370 23638 98039 2116 144490 16863 21807 12052 88572 36832 86716 37327 133565 22794 75471 46343 38269 23447 89136 45968 177375 19185 17108 5990 135669 6753 117358 35927 4138 3357 27...
output:
4
result:
ok single line: '4'
Test #14:
score: 0
Accepted
time: 89ms
memory: 96224kb
input:
99996 199988 0 0 41854 6629 75715 3077 164081 4911 163673 5475 134280 13391 154899 5665 181897 1823 38415 5848 188581 1312 126110 5509 47134 6766 31807 4743 96221 95900 104514 4582 45458 6738 126440 5611 138745 11284 161984 5687 72343 2492 160200 5783 46828 6673 15907 2194 112610 5327 82969 3780 749...
output:
4
result:
ok single line: '4'
Test #15:
score: -100
Wrong Answer
time: 6ms
memory: 52752kb
input:
19 33 0 0 12 11 22 11 11 6 10 1 10 4 11 9 17 17 17 10 17 15 13 12 11 7 17 2 34 0 6 2 17 16 11 8 21 12 13 5 14 3 10 11 1 14 18 16 6 19 9 2 11 2 18 3 15 5 8 3 15 4 1 15 14 5 1 8 17 15 9 10 7 1 17 7 5 6 12 19 18 10 8 16 9 3 6 4 19 13 7 14 13 17 11 16 13 5 2 8 12 17 2 7 12 4
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'