Submission #375777

# Submission time Handle Problem Language Result Execution time Memory
375777 2021-03-10T01:42:22 Z daniel920712 Two Antennas (JOI19_antennas) C++14
22 / 100
304 ms 82072 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;
struct A
{

    int l,r;
    int nxl,nxr;
    pair < int , int > ans;
}Node[1000005];
int all[1000005],now=1;
int l[1000005],r[1000005];
int x[1000005],y[1000005];
vector < pair < int , int > > in[1000005];
vector < pair < int , int > > out[1000005];
pair < int , int > operator+(pair < int , int > a,pair < int , int > b)
{
    return make_pair(max(a.first,b.first),min(a.second,b.second));
}
void build(int l,int r,int here)
{
    Node[here].l=l;
    Node[here].r=r;
    if(l==r)
    {
        Node[here].ans=make_pair(0,2e9);
        return;
    }
    Node[here].nxl=now++;
    Node[here].nxr=now++;
    build(l,(l+r)/2,Node[here].nxl);
    build((l+r)/2+1,r,Node[here].nxr);
    Node[here].ans=Node[Node[here].nxl].ans+Node[Node[here].nxr].ans;
}
void cha(int where,pair < int , int > con,int here)
{
    if(where==Node[here].l&&where==Node[here].r)
    {
        Node[here].ans=con;
        return;
    }
    if(where<=(Node[here].l+Node[here].r)/2) cha(where,con,Node[here].nxl);
    else cha(where,con,Node[here].nxr);
    Node[here].ans=Node[Node[here].nxl].ans+Node[Node[here].nxr].ans;
}
pair < int , int > Find(int l,int r,int here)
{
    if(l==Node[here].l&&r==Node[here].r) return Node[here].ans;
    if(r<=(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxl);
    else if(l>(Node[here].l+Node[here].r)/2) return Find(l,r,Node[here].nxr);
    else return Find(l,(Node[here].l+Node[here].r)/2,Node[here].nxl)+Find((Node[here].l+Node[here].r)/2+1,r,Node[here].nxr);
}
pair < int , int > tt;
int main()
{
    int N,M,ok=0,ans=0,i;
    scanf("%d",&N);
    for(i=1;i<=N;i++)
    {
        scanf("%d %d %d",&all[i],&l[i],&r[i]);
        if(i-l[i]>=1)
        {
            in[max(1,i-r[i])].push_back(make_pair(i,all[i]));
            out[i-l[i]+1].push_back(make_pair(i,all[i]));
        }
    }
    scanf("%d",&M);
    for(i=1;i<=M;i++) scanf("%d %d",&x[i],&y[i]);
    build(1,N,0);
    for(i=1;i<=N;i++)
    {
        for(auto j:in[i])
        {
            //printf("aa %d %d\n",i,j);
            cha(j.first,make_pair(j.second,j.second),0);
        }
        for(auto j:out[i]) cha(j.first,make_pair(0,2e9),0);
        if(i+l[i]<=N)
        {
            tt=Find(i+l[i],min(N,i+r[i]),0);
            if(tt.first) ans=max(ans,abs(all[i]-tt.first));
            if(tt.second!=2000000000) ans=max(ans,abs(all[i]-tt.second));
        }


    }
    if(ans==0) printf("-1\n");
    else printf("%d\n",ans);

    return 0;
}

Compilation message

antennas.cpp: In function 'int main()':
antennas.cpp:59:13: warning: unused variable 'ok' [-Wunused-variable]
   59 |     int N,M,ok=0,ans=0,i;
      |             ^~
antennas.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d",&N);
      |     ~~~~~^~~~~~~~~
antennas.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   63 |         scanf("%d %d %d",&all[i],&l[i],&r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
antennas.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   70 |     scanf("%d",&M);
      |     ~~~~~^~~~~~~~~
antennas.cpp:71:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   71 |     for(i=1;i<=M;i++) scanf("%d %d",&x[i],&y[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 70764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 70764 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 269 ms 76664 KB Output is correct
2 Correct 301 ms 81764 KB Output is correct
3 Correct 208 ms 78440 KB Output is correct
4 Correct 301 ms 81764 KB Output is correct
5 Correct 140 ms 75752 KB Output is correct
6 Correct 304 ms 82072 KB Output is correct
7 Correct 257 ms 80228 KB Output is correct
8 Correct 298 ms 81840 KB Output is correct
9 Correct 73 ms 72684 KB Output is correct
10 Correct 298 ms 81764 KB Output is correct
11 Correct 187 ms 77752 KB Output is correct
12 Correct 297 ms 81764 KB Output is correct
13 Correct 205 ms 81380 KB Output is correct
14 Correct 195 ms 81124 KB Output is correct
15 Correct 183 ms 79680 KB Output is correct
16 Correct 181 ms 79648 KB Output is correct
17 Correct 212 ms 81764 KB Output is correct
18 Correct 191 ms 80228 KB Output is correct
19 Correct 194 ms 80488 KB Output is correct
20 Correct 201 ms 80712 KB Output is correct
21 Correct 195 ms 81252 KB Output is correct
22 Correct 192 ms 80740 KB Output is correct
23 Correct 196 ms 80868 KB Output is correct
24 Correct 179 ms 79544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 70764 KB Output isn't correct
2 Halted 0 ms 0 KB -