結果
| 問題 |
No.947 ABC包囲網
|
| コンテスト | |
| ユーザー |
fgwiebfaoish
|
| 提出日時 | 2019-12-10 01:51:50 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 7,646 bytes |
| コンパイル時間 | 1,392 ms |
| コンパイル使用メモリ | 114,668 KB |
| 実行使用メモリ | 33,528 KB |
| 最終ジャッジ日時 | 2024-06-23 12:38:18 |
| 合計ジャッジ時間 | 7,298 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 5 TLE * 1 -- * 30 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
const int mod=(int)1e9+7;
static void Main(){
Sc sc=new Sc();
var n=sc.I;
var d=new double[n][];
var avl=new Avl();
for(int i = 0;i<n;i++) {
d[i]=sc.Da3(false,0,true,0);
d[i][2]=Atan2(d[i][1],d[i][0])*180/PI;
avl.Ud(d[i][2]);
}
long ans=0;
for(int i = 0;i<n-1;i++) {
for(int j = i+1;j<n;j++) {
var c1=d[i][2];
c1+=Sign(c1)==1?-180:180;
var c2=d[j][2];
c2+=Sign(c2)==1?-180:180;
if(c1>c2){
var e=c1;
c1=c2;
c2=e;
}
if(c1+180==c2){continue;}
if(c2-c1>180){
ans+=avl.Rg(c2+1e-9,1e9)+avl.Rg(-1e9,c1-1e-9);
}
else{
ans+=avl.Rg(c1+1e-9,c2-1e-9);
}
}
}
Console.WriteLine("{0}",ans/3);
}
}
public class Avl{
public class Nd{
public int h=1,c=1;
public readonly double n;
public Nd l,r;
public Nd(double n,Nd l,Nd r){this.n=n;this.l=l;this.r=r;}
}
public Nd root,du;
public int cnt=0;
public Avl(){
du=new Nd(int.MinValue,du,du);du.h=0;du.c=0;
root=du;
}
public void Ud(double n){
Nd mn=new Nd(n,du,du);
if(root==du){root=mn;}
else{
Fu(root,n,mn);
if(Abs(root.l.h-root.r.h)>1){root=Rotate(root);}
}
cnt++;
}
private void Fu(Nd t,double n,Nd mn){
t.c++;
if(t.n>n){
if(t.l!=du){
Fu(t.l,n,mn);
if(Abs(t.l.l.h-t.l.r.h)>1){t.l=Rotate(t.l);}
}
else{t.l=mn;}
}
else{
if(t.r!=du){
Fu(t.r,n,mn);
if(Abs(t.r.l.h-t.r.r.h)>1){t.r=Rotate(t.r);}
}
else{t.r=mn;}
}
t.h=Max(t.l.h,t.r.h)+1;
}
private Nd Rotate(Nd t){
Nd nd=du;
if(t.l.h>t.r.h){
if(t.l.l.h>t.l.r.h){
nd=t.l;t.l=t.l.r;nd.r=t;
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
}
else{
nd=t.l.r;
t.l.r=nd.l;nd.l=t.l;
t.l.h=Max(t.l.l.h,t.l.r.h)+1;
t.l.c=t.l.l.c+t.l.r.c+1;
t.l=nd.r;nd.r=t;
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
}
}
else{
if(t.r.l.h>t.r.r.h){
nd=t.r.l;
t.r.l=nd.r;nd.r=t.r;
t.r.h=Max(t.r.l.h,t.r.r.h)+1;
t.r.c=t.r.l.c+t.r.r.c+1;
t.r=nd.l;nd.l=t;
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
}
else{
nd=t.r;t.r=t.r.l;nd.l=t;
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
}
}
nd.h=Max(nd.l.h,nd.r.h)+1;
nd.c=nd.l.c+nd.r.c+1;
return nd;
}
public bool Dl(int n){
if(cnt==0){return false;}
Nd t=root;
if(t.n==n){
root=Fd2(root);
if(cnt==0){return true;}
else if(Abs(root.l.h-root.r.h)>1){root=Rotate(root);}
else{
root.h=Max(root.l.h,root.r.h)+1;
root.c=root.l.c+root.r.c+1;
}
return true;
}
bool bo=Fd1(root,n);
if(Abs(root.l.h-root.r.h)>1){root=Rotate(root);}
else{
root.h=Max(root.l.h,root.r.h)+1;
root.c=root.l.c+root.r.c+1;
}
return bo;
}
private bool Fd1(Nd t,int n){
if(t.n>n){
if(t.l==du){return false;}
else if(t.l.n!=n){
bool bo=Fd1(t.l,n);
if(Abs(t.l.l.h-t.l.r.h)>1){t.l=Rotate(t.l);}
else{
t.l.h=Max(t.l.l.h,t.l.r.h)+1;
t.l.c=t.l.l.c+t.l.r.c+1;
}
return bo;
}
else{
t.l=Fd2(t.l);
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
return true;
}
}
else{
if(t.r==du){return false;}
else if(t.r.n!=n){
bool bo=Fd1(t.r,n);
if(Abs(t.r.l.h-t.r.r.h)>1){t.r=Rotate(t.r);}
else{
t.r.h=Max(t.r.l.h,t.r.r.h)+1;
t.r.c=t.r.l.c+t.r.r.c+1;
}
return bo;
}
else{
t.r=Fd2(t.r);
t.h=Max(t.l.h,t.r.h)+1;
t.c=t.l.c+t.r.c+1;
return true;
}
}
}
private Nd Fd2(Nd dn){
cnt--;
if(dn.l==du){return dn.r;}
if(dn.r==du){return dn.l;}
Nd u=dn.l;
if(u.r==du){
u.r=dn.r;
u.h=Max(u.l.h,u.r.h)+1;
u.c=u.l.c+u.r.c+1;
return u;
}
u=Fd3(u,dn);
if(Abs(dn.l.l.h-dn.l.r.h)>1){u.l=Rotate(dn.l);}
else{
dn.l.h=Max(dn.l.l.h,dn.l.r.h)+1;
dn.l.c=dn.l.l.c+dn.l.r.c+1;
}
u.h=Max(u.l.h,u.r.h)+1;
u.c=u.l.c+u.r.c+1;
return u;
}
private Nd Fd3(Nd u,Nd dn){
if(u.r.r!=du){
Nd v=Fd3(u.r,dn);
if(Abs(u.r.l.h-u.r.r.h)>1){u.r=Rotate(u.r);}
else{
u.r.h=Max(u.r.l.h,u.r.r.h)+1;
u.r.c=u.r.l.c+u.r.r.c+1;
}
return v;
}
else{
Nd v=u.r;u.r=u.r.l;v.l=dn.l;v.r=dn.r;
return v;
}
}
public bool Hs(int n){
Nd t=root;
if(cnt==0){return false;}
if(t.n==n){return true;}
bool bo=false;
while(true){
if(t.n>n){
if(t.l==du){break;}
else if(t.l.n!=n){t=t.l;}
else{bo=true;break;}
}
else{
if(t.r==du){break;}
else if(t.r.n!=n){t=t.r;}
else{bo=true;break;}
}
}
return bo;
}
public Nd Ra(int n){return cnt>=n?Fr(root,n):null;}
private Nd Fr(Nd t,int n){
if(t.l.c>n-1){return Fr(t.l,n);}
if(t.l.c<n-1){return Fr(t.r,n-t.l.c-1);}
return t;
}
public Nd Lb(int n){return cnt!=0?Flb(root,n):null;}
private Nd Flb(Nd t,int n){
if(t.n<n){
if(t.r==du){return null;}
return Flb(t.r,n);
}
if(t.n>n){
if(t.l==du){return t;}
Nd u=Flb(t.l,n);
return u==null?t:u;
}
return t;
}
public Nd Ub(int n){return cnt!=0?Fub(root,n):null;}
private Nd Fub(Nd t,int n){
if(t.n>n){
if(t.l==du){return null;}
return Fub(t.l,n);
}
if(t.n<n){
if(t.r==du){return t;}
Nd u=Fub(t.r,n);
return u==null?t:u;
}
return t;
}
public int Rg(double a,double b){return cnt!=0?Frg(root,a,b,false,false):0;}
private int Frg(Nd t,double a,double b,bool l,bool r){
if(t.h==0){return 0;}
if(l&&r){return t.c;}
if(t.n<a){return Frg(t.r,a,b,t.n>=a,r);}
if(t.n>b){return Frg(t.l,a,b,l,t.n<=b);}
return Frg(t.l,a,b,l,t.n<=b)+Frg(t.r,a,b,t.n>=a,r)+1;
}
}
public class Sc{
public int I{get{return int.Parse(Console.ReadLine());}}
public long L{get{return long.Parse(Console.ReadLine());}}
public double D{get{return double.Parse(Console.ReadLine());}}
public string S{get{return Console.ReadLine();}}
public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
public string[] Sa{get{return Console.ReadLine().Split();}}
public object[] Oa{get{return Console.ReadLine().Split();}}
public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
fgwiebfaoish