Submission #1102507

#TimeUsernameProblemLanguageResultExecution timeMemory
1102507LTTrungCHLElection (BOI18_election)C++17
28 / 100
5 ms1108 KiB
///***LTT***/// /// ->NHAT QUOC GIA<- /// #include<bits/stdc++.h> //#pragma GCC optimize ("O3") //#pragma GCC optimize ("unroll-loops") //#pragma GCC target("popcnt") //#define int long long #define endl "\n" #define F first #define S second #define pb push_back using namespace std; vector <int> lg2; //void MAKE_LOG_ARR(int n){ // lg2.resize(n + 3); // for (int i = 1;i <= n;++i){ // lg2[i] = __lg(i); // } //} const long long oo = 1e9+7; const int N = 5 * 1e5 + 10; int n, q, a[N]; string s; namespace sub1{ int pre[2002], sur[2002], b[2002]; void solve(){ while (q--){ int l, r; cin >> l >> r; for (int i = l;i <= r;++i){ b[i] = a[i]; } int ans = 0; for (int i = l;i <= r;++i){ pre[i] = (i == l ? 0 : pre[i - 1] ) + b[i]; if (pre[i] < 0){ b[i] = 0; ++ans; ++pre[i]; } } for (int i = r;i >= l;--i){ sur[i] = (i == r ? 0 : sur[i + 1] ) + b[i]; if (sur[i] < 0){ b[i] = 0; ++ans; ++sur[i]; } } cout << ans <<"\n"; } return; } }; void solve(){ cin >> n; cin >> s; for (int i = 0;i < s.size();++i){ if (s[i] == 'T'){ a[i + 1] = -1; } else a[i + 1] = 1; } cin >> q; if (n <= 2000 and q <= 2000){ sub1::solve(); return; } return; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); if (fopen("ltt.inp", "r")){ freopen("ltt.inp", "r", stdin); freopen("ltt.out", "w", stdout); } // int t; // cin >> t; // while(t--){ solve(); // } return 0; }

Compilation message (stderr)

election.cpp: In function 'void solve()':
election.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0;i < s.size();++i){
      |                    ~~^~~~~~~~~~
election.cpp: In function 'int main()':
election.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen("ltt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
election.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("ltt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...