제출 #481194

#제출 시각아이디문제언어결과실행 시간메모리
481194uroskElection (BOI18_election)C++14
100 / 100
724 ms39984 KiB
// __builtin_popcount(x) broj bitova
// __builtin_popcountll(x) long long
#define here cerr<<"---------------------------\n"
#include "bits/stdc++.h"
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define ull unsigned long long
#define llinf 100000000000000000LL // 10^17
#define iinf 2000000000 // 2*10^9
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define rall(a) a.begin(),a.end(),greater<int>()
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void setIO(string inoutname)
{
	freopen((inoutname+".in").c_str(),"r",stdin);
    	freopen((inoutname+".out").c_str(),"w",stdout);
}
#define mod 1
ll gcd(ll a, ll b)
{
   if(b==0) return a;
   if(a==0) return b;
   if(a>=b)  return gcd(a%b,b);
   return  gcd(a,b%a);
}
ll lcm(ll a,ll b){
   return (a/gcd(a,b))*b;
}
ll add(ll a,ll b){
	a+=b;
	a+=mod;
	if(a>=mod) a%=mod;
	return a;
}
ll mul(ll a,ll b){return(a*b)%mod;}
#define maxn 500005
ll n,q;
ll a[maxn];
struct node{
    ll l,r,s,ans;
    node operator+(node b){
        node rez;
        rez.l = max(l,s+b.l);
        rez.r = max(b.r,r+b.s);
        rez.s = s + b.s;
        rez.ans = max({l+b.r,ans+b.s,s+b.ans});
        return rez;
    }
};
node t[4*maxn];
void init(ll v,ll tl,ll tr){
    if(tl==tr){
        if(a[tl]==1) t[v] = {1,1,1,1};
        else t[v] = {0,0,-1,0};
        return;
    }
    ll mid = (tl+tr)/2;
    init(2*v,tl,mid);
    init(2*v+1,mid+1,tr);
    t[v] = t[2*v]+t[2*v+1];
}
node reshi(ll v,ll tl,ll tr,ll l,ll r){
    if(l>r) return {0,0,0,0};
    if(tl==l&&tr==r) return t[v];
    ll mid = (tl+tr)/2;
    return reshi(2*v,tl,mid,l,min(mid,r)) + reshi(2*v+1,mid+1,tr,max(l,mid+1),r);
}
void tc(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n;
    for(ll i = 1;i<=n;i++){
        char c;
        cin >> c;
        if(c=='T') a[i] = 1;
        else a[i] = -1;
    }
    init(1,1,n);
    cin >> q;
    while(q--){
        ll l,r; cin >> l >> r;
        cout<<reshi(1,1,n,l,r).ans<<endl;
    }
}
int main(){
	ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
	//setIO("lol");
	int t; t = 1;
	while(t--){
		tc();
	}
	return 0;
}

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

election.cpp: In function 'void setIO(std::string)':
election.cpp:32:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |  freopen((inoutname+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
election.cpp:33:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |      freopen((inoutname+".out").c_str(),"w",stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...