Submission #794989

# Submission time Handle Problem Language Result Execution time Memory
794989 2023-07-27T04:58:33 Z Amylopectin Election (BOI18_election) C++14
0 / 100
2 ms 320 KB
#include <stdio.h>
#include <iostream>
using namespace std;
const long long mxn = 4e6 + 10;
char s[mxn] = {};
long long ta[mxn] = {},semi[mxn] = {},sema[mxn] = {},ama,ami;
long long bui(long long cl,long long cr,long long no)
{
    if(cl == cr)
    {
        semi[no] = ta[cl];
        sema[no] = ta[cl];
        return 0;
    }
    long long mid = (cl+cr) / 2;
    bui(cl,mid,no*2);
    bui(mid+1,cr,no*2+1);
    sema[no] = max(sema[no*2],sema[no*2+1]);
    semi[no] = min(semi[no*2],semi[no*2+1]);
    return 0;
}
long long fii(long long cl,long long cr,long long no,long long tl,long long tr)
{
    if(tl > cr || tr < cl)
    {
        ami = mxn;
        ama = 0;
        return 0;
    }
    if(cl >= tl && cr <= tr)
    {
        ami = semi[no];
        ama = sema[no];
        return 0;
    }
    long long mid = (cl+cr) / 2,cmi,cma;
    fii(cl,mid,no*2,tl,tr);
    cmi = ami;
    cma = ama;
    fii(mid+1,cr,no*2+1,tl,tr);
    ami = min(cmi,ami);
    ama = max(cma,ama);
    return 0;
}
int main()
{
    long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
    scanf("%lld %s %lld",&n,&s,&q);
    for(i=1; i<=n; i++)
    {
        if(s[i-1] == 'C')
        {
            ta[i] = ta[i-1] - 1;
        }
        else 
        {
            ta[i] = ta[i-1] + 1;
        }
    }
    bui(0,n,1);
    for(i=0; i<q; i++)
    {
        scanf("%lld %lld",&cl,&cr);
        fii(0,n,1,cl-1,cr);
        ans = max(ama - ta[cl-1],ta[cr] - ami);
        printf("%lld\n",ans);
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:48:18: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[4000010]' [-Wformat=]
   48 |     scanf("%lld %s %lld",&n,&s,&q);
      |                 ~^          ~~
      |                  |          |
      |                  char*      char (*)[4000010]
election.cpp:47:17: warning: unused variable 'j' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                 ^
election.cpp:47:21: warning: unused variable 'm' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                     ^
election.cpp:47:25: warning: unused variable 'cn' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                         ^~
election.cpp:47:28: warning: unused variable 'cm' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                            ^~
election.cpp:47:31: warning: unused variable 'fn' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                               ^~
election.cpp:47:34: warning: unused variable 'fm' [-Wunused-variable]
   47 |     long long i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                                  ^~
election.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |     scanf("%lld %s %lld",&n,&s,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         scanf("%lld %lld",&cl,&cr);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 320 KB Output isn't correct
2 Halted 0 ms 0 KB -