QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#359544 | #5558. Formula Flatland | crsfaa# | WA | 151ms | 163940kb | C++14 | 3.7kb | 2024-03-20 18:59:35 | 2024-03-20 18:59:38 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
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=1e6+5,M=2e6+5;const db eps=1e-12;
#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);
}
}
const int mxn=5e5;
namespace syh
{
vector<int> a[mxn];
int deg[mxn];
pair<int,int> e[mxn];
int col[mxn];
void work(int n,int m)
{
int i,j,x,y,s=0;
for(i=1;i<=m;i++)
deg[e[i].first]++,
deg[e[i].second]++;
for(i=1;i<=m;i++)
a[min(pair<int,int>{deg[e[i].first],e[i].first},{deg[e[i].second],e[i].second}).second].push_back(max(pair<int,int>{deg[e[i].first],e[i].first},{deg[e[i].second],e[i].second}).second);
for(i=1;i<=n;i++)
{
for(auto j:a[i]) col[j]=i;
for(auto j:a[i])
for(auto k:a[j])
if(col[k]==i)
{
cout<<3;
exit(0);
}
}
}
}
signed 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),syh::e[i]={x,y};
syh::work(n,m);
build(),dfs(rt,0),work();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 12ms
memory: 96204kb
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: 98268kb
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: 7ms
memory: 96268kb
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: 7ms
memory: 98328kb
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: 7ms
memory: 98204kb
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: 96176kb
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: 18ms
memory: 96272kb
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: 8ms
memory: 96200kb
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: 12ms
memory: 96212kb
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: 11ms
memory: 98220kb
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: 119ms
memory: 159652kb
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: 126ms
memory: 157440kb
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: 143ms
memory: 158012kb
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: 151ms
memory: 163940kb
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: 0
Accepted
time: 16ms
memory: 96268kb
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:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 7ms
memory: 98224kb
input:
40 62 0 0 62 12 58 9 28 20 34 20 24 21 70 5 4 3 47 21 58 16 14 1 30 19 66 4 35 31 38 38 72 3 43 29 62 2 30 22 37 34 38 35 47 24 14 13 65 8 15 5 57 3 20 18 41 28 9 7 17 12 38 36 42 22 34 25 63 6 38 37 51 22 7 2 76 0 39 33 32 27 1 38 32 5 21 20 22 32 29 37 20 31 14 40 34 26 40 19 33 40 10 27 30 27 28 ...
output:
4
result:
ok single line: '4'
Test #17:
score: 0
Accepted
time: 89ms
memory: 138300kb
input:
99999 199994 0 0 79608 40849 85311 57397 91861 76158 74680 26575 88905 67730 66013 1745 81778 47143 92487 77951 78943 38927 68142 7862 78467 37616 93241 80166 71640 17863 71193 16602 78612 37974 67666 6505 94807 84668 72445 20114 88308 66030 94434 83618 73474 23094 78102 36534 91676 75634 90949 7358...
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 149ms
memory: 160696kb
input:
100000 199996 0 0 79627 40847 85331 57394 91794 76160 74662 26574 88864 67731 66083 1746 81801 47143 92412 77953 78963 38925 68217 7859 78485 37613 93171 80168 71670 17858 71242 16598 78619 37974 67728 6501 94728 84673 72426 20115 88327 66034 94377 83620 73480 23093 78113 36533 91620 75636 90912 735...
output:
4
result:
ok single line: '4'
Test #19:
score: -100
Wrong Answer
time: 10ms
memory: 98204kb
input:
52 80 0 0 77 2 45 37 14 10 10 3 100 0 95 4 82 3 82 8 77 5 84 12 50 47 50 48 5 4 50 50 85 5 83 10 87 11 50 49 93 6 25 10 38 10 48 9 64 11 45 30 33 13 35 12 39 16 43 13 45 15 60 10 55 18 48 26 45 29 29 14 42 22 43 20 50 16 46 25 44 27 33 1 74 3 16 8 13 2 34 5 71 6 43 34 20 6 35 9 44 7 68 8 45 31 6 7 7...
output:
5
result:
wrong answer 1st lines differ - expected: '4', found: '5'