답안 #852166

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
852166 2023-09-21T11:09:45 Z MilosMilutinovic Tri (CEOI09_tri) C++14
50 / 100
2000 ms 10320 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> B;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=100100;
const int L=20;
int n,m,st[N][L],logs[N];
ll d[N];

struct pt {
	int x,y;
	pt(int _x=0,int _y=0) : x(_x),y(_y) {}
}p[N];
int orient(pt a,pt b,pt c) {
	ll v=(b.y-a.y)*1ll*(c.x-b.x)-(b.x-a.x)*1ll*(c.y-b.y);
	return v==0?0:(v<0?-1:1);
}
bool const operator<(const pt& a,const pt& b) {
	if (orient(pt(0,0),a,b)==0) {
		return (a.x==b.x?a.y<b.y:a.x<b.x);
	}
	return orient(pt(0,0),a,b)<0;
}
bool in_tri(pt a,pt b,pt c,pt p) {
	return orient(a,b,p)!=1&&orient(b,c,p)!=1&&orient(c,a,p)!=1;
}
int cmp(int i,int j) {
	return d[i]<d[j]?i:j;
}
int query(int l,int r) {
	int k=logs[r-l+1];
	return cmp(st[l][k],st[r-(1<<k)+1][k]);
}
int main() {
	scanf("%d%d",&n,&m);
	rep(i,0,n) {
		scanf("%d%d",&p[i].x,&p[i].y);
	}
	sort(p,p+n);
	rep(i,0,n) {
		st[i][0]=i;
		d[i]=p[i].x*1ll*p[i].x+p[i].y*1ll*p[i].y;
	}
	rep(i,2,n+1) logs[i]=logs[i>>1]+1;
	rep(j,1,L) {
		rep(i,0,n-(1<<j)+1) {
			st[i][j]=cmp(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		}
	}
	while (m--) {
		pt a,b;
		scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
		if (orient(b,pt(0,0),a)>=0) swap(a,b);
		int L,R;
		{
			L=n-1;
			int low=0,high=n-1;
			while (low<=high) {
				int mid=low+high>>1;
				if (orient(p[mid],pt(0,0),a)<=0) {
					L=mid;
					high=mid-1;
				} else {
					low=mid+1;
				}
			}
		}
		{
			R=0;
			int low=0,high=n-1;
			while (low<=high) {
				int mid=low+high>>1;
				if (orient(p[mid],pt(0,0),b)>=0) {
					R=mid;
					low=mid+1;
				} else {
					high=mid-1;
				}
			}
		}
		if (L>R) {
			printf("N\n");
			continue;
		}
		bool ok=false;
		rep(i,L,R+1) if (in_tri(a,b,pt(0,0),p[i])) ok=true;
		puts(ok?"Y":"N");
	}
}

Compilation message

tri.cpp: In function 'int main()':
tri.cpp:78:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   78 |     int mid=low+high>>1;
      |             ~~~^~~~~
tri.cpp:91:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   91 |     int mid=low+high>>1;
      |             ~~~^~~~~
tri.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
tri.cpp:56:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d%d",&p[i].x,&p[i].y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp:71:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |   scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2648 KB Output is correct
2 Correct 5 ms 2904 KB Output is correct
3 Execution timed out 2036 ms 7260 KB Time limit exceeded
4 Execution timed out 2025 ms 7256 KB Time limit exceeded
5 Execution timed out 2041 ms 10320 KB Time limit exceeded
6 Execution timed out 2027 ms 9068 KB Time limit exceeded
7 Execution timed out 2059 ms 10212 KB Time limit exceeded
8 Correct 1564 ms 9092 KB Output is correct
9 Correct 1764 ms 9812 KB Output is correct
10 Correct 1971 ms 10280 KB Output is correct