제출 #486480

#제출 시각아이디문제언어결과실행 시간메모리
486480MilosMilutinovicElection (BOI18_election)C++14
0 / 100
1 ms448 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; const ll mod2=998244353; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=101000; int n,q; char s[N]; struct node { int pf,sf,s,f; }nd[4*N]; node comb(node x,node y) { node ret; ret.pf=max(x.pf,x.s+y.pf); ret.sf=max(y.sf,y.s+x.sf); ret.s=x.s+y.s; ret.f=max({x.f+y.s,x.s+y.f,x.pf+y.sf}); return ret; } void build(int p,int l,int r) { if (l==r) { if (s[l]=='C') { nd[p].pf=nd[p].sf=nd[p].s=nd[p].f=1; } else { nd[p].pf=nd[p].sf=nd[p].s=nd[p].f=0; } } else { int md=l+r>>1; build(p+p,l,md); build(p+p+1,md+1,r); nd[p]=comb(nd[p+p],nd[p+p+1]); } } node get(int p,int l,int r,int ql,int qr) { if (ql>r||qr<l) return {0,0,0,0}; if (ql<=l&&r<=qr) return nd[p]; int md=l+r>>1; return comb(get(p+p,l,md,ql,qr),get(p+p+1,md+1,r,ql,qr)); } int main() { scanf("%d",&n); scanf("%s",s+1); scanf("%d",&q); build(1,1,n); while (q--) { int l,r; scanf("%d%d",&l,&r); printf("%d\n",r-l+1-get(1,1,n,l,r).f); } }

컴파일 시 표준 에러 (stderr) 메시지

election.cpp: In function 'void build(int, int, int)':
election.cpp:46:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |   int md=l+r>>1;
      |          ~^~
election.cpp: In function 'node get(int, int, int, int, int)':
election.cpp:55:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |  int md=l+r>>1;
      |         ~^~
election.cpp: In function 'int main()':
election.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%d",&n);
      |  ~~~~~^~~~~~~~~
election.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%s",s+1);
      |  ~~~~~^~~~~~~~~~
election.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
election.cpp:66:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |   scanf("%d%d",&l,&r);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...