Submission #794978

# Submission time Handle Problem Language Result Execution time Memory
794978 2023-07-27T04:50:19 Z Amylopectin Election (BOI18_election) C++14
0 / 100
2 ms 320 KB
#include <stdio.h>
#include <iostream>
using namespace std;
const int mxn = 4e6 + 10;
char s[mxn] = {};
int ta[mxn] = {},semi[mxn] = {},sema[mxn] = {},ama,ami;
int bui(int cl,int cr,int no)
{
    if(cl == cr)
    {
        semi[no] = ta[cl];
        sema[no] = ta[cl];
        return 0;
    }
    int 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;
}
int fii(int cl,int cr,int no,int tl,int 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;
    }
    int 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()
{
    int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
    scanf("%d %s %d",&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("%d %d",&cl,&cr);
        fii(0,n,1,cl-1,cr);
        ans = max(ama - ta[cl-1],ta[cr] - ami);
        printf("%d\n",ans);
    }
    return 0;
}

Compilation message

election.cpp: In function 'int main()':
election.cpp:48:16: warning: format '%s' expects argument of type 'char*', but argument 3 has type 'char (*)[4000010]' [-Wformat=]
   48 |     scanf("%d %s %d",&n,&s,&q);
      |               ~^        ~~
      |                |        |
      |                char*    char (*)[4000010]
election.cpp:47:11: warning: unused variable 'j' [-Wunused-variable]
   47 |     int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |           ^
election.cpp:47:15: warning: unused variable 'm' [-Wunused-variable]
   47 |     int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |               ^
election.cpp:47:19: warning: unused variable 'cn' [-Wunused-variable]
   47 |     int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                   ^~
election.cpp:47:22: warning: unused variable 'cm' [-Wunused-variable]
   47 |     int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                      ^~
election.cpp:47:25: warning: unused variable 'fn' [-Wunused-variable]
   47 |     int i,j,n,m,q,cn,cm,fn,fm,cl,cr,ans;
      |                         ^~
election.cpp:47:28: warning: unused variable 'fm' [-Wunused-variable]
   47 |     int 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("%d %s %d",&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("%d %d",&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 -