Submission #888605

#TimeUsernameProblemLanguageResultExecution timeMemory
888605ad_redTri (CEOI09_tri)C++17
100 / 100
505 ms6484 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i,a,n) for (ll i=a;i<n;i++) #define per(i,a,n) for (ll 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) ((ll)(x).size()) typedef vector<ll> VI; typedef basic_string<int> B; typedef pair<ll,ll> PII; // head const ll N=100100; const ll S=1200; ll n,m; struct pt { ll x,y; pt(ll _x=0,ll _y=0) : x(_x),y(_y) {} }p[N]; ll vp(pt a, pt b) { return a.x * b.y - b.x * a.y; } vector<pt> ch[N]; ll 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); } ll sgn(pt a, pt b, pt c) { // -1 if the order is A-B-C from left to right if B is the bottom point // 1 or 0 otherwise ll q = (a.x - b.x) * (c.y - b.y) - (a.y - b.y) * (c.x - b.x); return q == 0 ? 0 : (q < 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; } signed 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) { ch[i/S].pb(p[i]); } rep(i,0,n) { if (ch[i].empty()) continue; vector<pt> hull; sort(all(ch[i]),[&](pt a,pt b) { return a.x<b.x||(a.x==b.x&&a.y<b.y); }); for (auto& p:ch[i]) { while (SZ(hull)>=2 && sgn(hull[SZ(hull)-2], p, hull[SZ(hull)-1]) <= 0LL) { hull.pop_back(); } hull.pb(p); } ch[i]=hull; } 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); ll L,R; { L=n-1; ll low=0,high=n-1; while (low<=high) { ll mid=low+high>>1; if (orient(p[mid],pt(0,0),a)>=0) { L=mid; high=mid-1; } else { low=mid+1; } } } { R=0; ll low=0,high=n-1; while (low<=high) { ll 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; } if (R-L<=S) { bool ok=false; rep(i,L,R+1) if (in_tri(a,b,pt(0,0),p[i])) ok=true; puts(ok?"Y":"N"); continue; } bool ok=false; while (L%S!=0) { if (in_tri(a,b,pt(0,0),p[L])) ok=true; L++; } while (R>=L&&R%S!=S-1) { if (in_tri(a,b,pt(0,0),p[R])) ok=true; R--; } rep(i,L/S,R/S+1) { ll sz=SZ(ch[i]); ll low=0,high=sz-1; while (low<=high) { ll mid=low+high>>1; if (in_tri(a,b,pt(0,0),ch[i][mid])) { ok=true; break; } if (mid+1==sz||(!in_tri(a,b,pt(0,0),ch[i][mid+1])&&orient(ch[i][mid],a,ch[i][mid+1])==1)) { high=mid-1; } else { low=mid+1; } } if (ok) break; } puts(ok?"Y":"N"); } }

Compilation message (stderr)

tri.cpp: In function 'int main()':
tri.cpp:57:11: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll*' {aka 'long long int*'} [-Wformat=]
   57 |   scanf("%d%d",&n,&m);
      |          ~^    ~~
      |           |    |
      |           int* ll* {aka long long int*}
      |          %lld
tri.cpp:57:13: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll*' {aka 'long long int*'} [-Wformat=]
   57 |   scanf("%d%d",&n,&m);
      |            ~^     ~~
      |             |     |
      |             int*  ll* {aka long long int*}
      |            %lld
tri.cpp:59:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll*' {aka 'long long int*'} [-Wformat=]
   59 |     scanf("%d%d",&p[i].x,&p[i].y);
      |            ~^    ~~~~~~~
      |             |    |
      |             int* ll* {aka long long int*}
      |            %lld
tri.cpp:59:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll*' {aka 'long long int*'} [-Wformat=]
   59 |     scanf("%d%d",&p[i].x,&p[i].y);
      |              ~^          ~~~~~~~
      |               |          |
      |               int*       ll* {aka long long int*}
      |              %lld
tri.cpp:79:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'll*' {aka 'long long int*'} [-Wformat=]
   79 |     scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |            ~^        ~~~~
      |             |        |
      |             int*     ll* {aka long long int*}
      |            %lld
tri.cpp:79:15: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'll*' {aka 'long long int*'} [-Wformat=]
   79 |     scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |              ~^           ~~~~
      |               |           |
      |               int*        ll* {aka long long int*}
      |              %lld
tri.cpp:79:17: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'll*' {aka 'long long int*'} [-Wformat=]
   79 |     scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |                ~^              ~~~~
      |                 |              |
      |                 int*           ll* {aka long long int*}
      |                %lld
tri.cpp:79:19: warning: format '%d' expects argument of type 'int*', but argument 5 has type 'll*' {aka 'long long int*'} [-Wformat=]
   79 |     scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |                  ~^                 ~~~~
      |                   |                 |
      |                   int*              ll* {aka long long int*}
      |                  %lld
tri.cpp:86:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |         ll mid=low+high>>1;
      |                ~~~^~~~~
tri.cpp:99:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   99 |         ll mid=low+high>>1;
      |                ~~~^~~~~
tri.cpp:131:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  131 |         ll mid=low+high>>1;
      |                ~~~^~~~~
tri.cpp:57:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d",&n,&m);
      |   ~~~~~^~~~~~~~~~~~~~
tri.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |     scanf("%d%d",&p[i].x,&p[i].y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
tri.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |     scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...