Submission #1059893

#TimeUsernameProblemLanguageResultExecution timeMemory
1059893ThanhsEkoeko (COCI21_ekoeko)C++14
110 / 110
9 ms6036 KiB
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; #define int long long // #define double long double #define endl '\n' #define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define setmin(x, y) x = min((x), (y)) #define setmax(x, y) x = max((x), (y)) #define sqr(x) ((x) * (x)) #define fi first #define se second #define all(x) x.begin(), x.end() // mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count()); // int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);} const int NM = 2e5 + 5; int n, bit[NM], type[NM], cnt[NM], ans; string s, ss[2]; queue<int> q[26]; void upd(int i) { for (; i <= n; i += i & -i) bit[i]++; } int get(int i) { int res = 0; for (; i; i -= i & -i) res += bit[i]; return res; } int get(int l, int r) { return get(r) - get(l - 1); } void solve() { cin >> n >> s; n = s.size(); for (char &c : s) c -= 'a'; for (int i = 0; i < n; i++) cnt[s[i]]++; for (int i = 0; i < 26; i++) cnt[i] /= 2; int t = 0; for (int i = 0; i < n; i++) { type[i] = (cnt[s[i]] ? 0 : 1); ss[type[i]] += s[i]; cnt[s[i]] = max(0ll, cnt[s[i]] - 1); if (!type[i]) ans += t; else t++; } n /= 2; for (int i = 0; i < n; i++) q[ss[0][i]].push(i + 1); for (int i = 0; i < n; i++) { int a = q[ss[1][i]].front(); q[ss[1][i]].pop(); ans += get(a, n); upd(a); } cout << ans; } signed main() { fastIO if (fopen("in.txt", "r")) { freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } int tc = 1; // cin >> tc; while (tc--) solve(); }

Compilation message (stderr)

Main.cpp: In function 'void solve()':
Main.cpp:52:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   52 |         cnt[s[i]]++;
      |                 ^
Main.cpp:58:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   58 |         type[i] = (cnt[s[i]] ? 0 : 1);
      |                            ^
Main.cpp:60:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |         cnt[s[i]] = max(0ll, cnt[s[i]] - 1);
      |                 ^
Main.cpp:60:38: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |         cnt[s[i]] = max(0ll, cnt[s[i]] - 1);
      |                                      ^
Main.cpp:68:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   68 |         q[ss[0][i]].push(i + 1);
      |                   ^
Main.cpp:71:27: warning: array subscript has type 'char' [-Wchar-subscripts]
   71 |         int a = q[ss[1][i]].front();
      |                           ^
Main.cpp:72:19: warning: array subscript has type 'char' [-Wchar-subscripts]
   72 |         q[ss[1][i]].pop();
      |                   ^
Main.cpp: In function 'int main()':
Main.cpp:84:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:85:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...