제출 #1146534

#제출 시각아이디문제언어결과실행 시간메모리
1146534Kaztaev_AlisherElection (BOI18_election)C++20
0 / 100
1 ms320 KiB
#include <bits/stdc++.h> #define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout) #define all(a) a.begin() , a.end() #define F first #define S second using namespace std; using ll = long long; const int N = 5e5+5 , inf = 1e9 + 7; const ll INF = 1e18 , mod = 1e9+7; int t[N*4]; int t2[N*4]; int a[N] , n , q , pr[N] , sf[N]; void build(int v, int tl , int tr){ if(tl == tr){ t[v] = pr[tl]; t2[v] = sf[tl]; return; } int tm = (tl+tr) >> 1; build(v*2,tl,tm); build(v*2+1,tm+1,tr); t[v] = min(t[v*2],t[v*2+1]); t2[v] = min(t2[v*2],t2[v*2+1]); } int get(int v, int tl , int tr , int l , int r){ if(l <= tl && tr <= r) return t[v]; if(tl > r || tr < l) return inf; int tm = (tl+tr) >> 1; return min(get(v*2,tl,tm,l,r) , get(v*2+1,tm+1,tr,l,r)); } int get2(int v, int tl , int tr , int l , int r){ if(l <= tl && tr <= r) return t2[v]; if(tl > r || tr < l) return inf; int tm = (tl+tr) >> 1; return min(get2(v*2,tl,tm,l,r) , get2(v*2+1,tm+1,tr,l,r)); } signed main(){ ios; file("elections"); cin >> n; string s; cin >> s; s = "0"+s; for(int i = 1; i <= n; i++){ pr[i] = pr[i-1]-(s[i] == 'T') +(s[i] == 'C'); } for(int i = n; i >= 1; i--){ sf[i] = sf[i+1]-(s[i] == 'T') +(s[i] == 'C'); } build(1,1,n); cin >> q; while(q--){ int l , r; cin >> l >> r; int resl = get(1,1,n,l,r)-pr[l-1]; int resr = get2(1,1,n,l,r)-sf[r+1]; if(min(resl,resr) > 0) cout << 0 << "\n"; else cout << max(abs(resl) , abs(resr)) << "\n"; } return 0; }

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

election.cpp: In function 'int main()':
election.cpp:4:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
election.cpp:47:9: note: in expansion of macro 'file'
   47 |         file("elections");
      |         ^~~~
election.cpp:4:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
election.cpp:47:9: note: in expansion of macro 'file'
   47 |         file("elections");
      |         ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...