Submission #259220

# Submission time Handle Problem Language Result Execution time Memory
259220 2020-08-07T12:24:11 Z 문홍윤(#5063) None (JOI12_constellation) C++17
0 / 100
68 ms 4856 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<LL, LL> pll;
const LL mod1=1000000007;

pll operator-(pll a, pll b){return mp(a.F-b.F, a.S-b.S);}
LL ccw(pll a, pll b){return a.F*b.S-a.S*b.F;}

int n;
pair<pll, int> p[100010];
vector<int> uh, dh;
int arr[200010], re, sum1[200010], sum2[200010];
int qn, on, tn, h0, h1, h2;
LL ret;


int main(){
    scanf("%d", &n);
    for(int i=1; i<=n; i++){
        scanf("%lld %lld %d", &p[i].F.F, &p[i].F.S, &p[i].S);
        if(p[i].S==0)qn++;
        if(p[i].S==1)on++;
        if(p[i].S==2)tn++;
    }
    sort(p+1, p+n+1);
    dh.eb(1); dh.eb(2);
    for(int i=3; i<=n; i++){
        while(dh.size()>1){
            int p1=dh[dh.size()-2], p2=dh[dh.size()-1];
            if(ccw(p[p2].F-p[p1].F, p[i].F-p[p2].F)>0)break;
            dh.pop_back();
        }
        dh.eb(i);
    }
    uh.eb(n); uh.eb(n-1);
    for(int i=n-2; i>=1; i--){
        while(uh.size()>1){
            int p1=uh[uh.size()-2], p2=uh[uh.size()-1];
            if(ccw(p[p2].F-p[p1].F, p[i].F-p[p2].F)>0)break;
            uh.pop_back();
        }
        uh.eb(i);
    }
    for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
    for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
    for(int i=0; i<re; i++){
        if(arr[i]==0)h0++;
        if(arr[i]==1)h1++;
        if(arr[i]==2)h2++;
    }
    for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
    for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
    for(int i=0; i<re; i++){
        if(i)sum1[i]=sum1[i-1], sum2[i]=sum2[i-1];
        if(arr[i]==1)sum1[i]++;
        if(arr[i]==2)sum2[i]++;
    }
    for(int i=0; i<re/2; i++){
        int nw1=0, nw2=0;
        if(i)nw1=sum1[i-1], nw2=sum2[i-1];
        int f1=lower_bound(sum1, sum1+re, nw1+h1)-sum1;
        int f2=lower_bound(sum2, sum2+re, nw2+1)-sum2;
        //printf("! %d %d\n", f1, f2);
        int tmp=min(i+re-1, f2)-max(i, f1);
        if(tmp>0){ret+=tmp; ret%=mod1;}
    }
    if(!h1)ret++;
    if(!h2)ret++;
    for(int i=1; i<=qn-h0; i++){ret*=2; ret%=mod1;}
    if(!on)ret--;
    if(!tn)ret--;
    printf("%lld", (ret+mod1)%mod1);
}

Compilation message

constellation.cpp: In function 'int main()':
constellation.cpp:49:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
                  ~^~~~~~~~~~~~
constellation.cpp:50:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
                  ~^~~~~~~~~~~~
constellation.cpp:56:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<dh.size()-1; i++)arr[re++]=p[dh[i]].S;
                  ~^~~~~~~~~~~~
constellation.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<uh.size()-1; i++)arr[re++]=p[uh[i]].S;
                  ~^~~~~~~~~~~~
constellation.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
constellation.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld %d", &p[i].F.F, &p[i].F.S, &p[i].S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 0 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 3 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 60 ms 4856 KB Output is correct
3 Incorrect 1 ms 384 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 68 ms 4728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 62 ms 2680 KB Output is correct
3 Incorrect 56 ms 2680 KB Output isn't correct
4 Halted 0 ms 0 KB -