Submission #1730878
Source Code Expand
// see https://gist.github.com/LumaKernel/ff55d49ee1af69b7388f15b707e75c15
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>
#include <random>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<P> VP;
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RREP(i,n) RFOR(i,0,n)
#define LFOR(i,a,b) for(ll i=(a);i<(b);++i)
#define RLFOR(i,b,a) for(ll i=(b)-1;i>=(a);--i)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE(a) (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define PB push_back
#define EACH(i,c) REP(i,(int)(c).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define dump(x) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";
#define dump2(x,y) cerr << "[L " << __LINE__ << "] " << #x << " = " << (x)\
<< " , " << #y << " = " << (y) << "\n";
const int INF = 1e9;
const double EPS = 1e-10;
const int _N = 2e5 + 100;
int n,m;
ll k;
string s;
struct BIT{
int data[_N];
int n;
void init(int n){
this->n = n;
REP(i, n+1)data[i] = 0;
}
void add(int i, int x){
i++;
while(i<=n){
data[i] += x;
i += i&-i;
}
}
int sum(int i){
i++;
int s = 0;
while(i>=1){
s += data[i];
i -= i&-i;
}
return s;
}
};
BIT letters[26];
int main() {
cin >> s;
n = s.size();
ll ans = 1;
REP(i, 26) letters[i].init(n);
REP(i, n) letters[s[i]%26].add(i, 1);
FOR(i, 1, n){
ans += i-letters[s[i]%26].sum(i-1);
}
cout << ans;
cout << endl;
}
Submission Info
Submission Time |
|
Task |
B - Reverse and Compare |
User |
luma |
Language |
C++14 (GCC 5.4.1) |
Score |
500 |
Code Size |
1921 Byte |
Status |
AC |
Exec Time |
22 ms |
Memory |
20868 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample_01.txt, sample_02.txt, sample_03.txt |
All |
sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt |
Case Name |
Status |
Exec Time |
Memory |
sample_01.txt |
AC |
4 ms |
16640 KB |
sample_02.txt |
AC |
4 ms |
16640 KB |
sample_03.txt |
AC |
4 ms |
16640 KB |
subtask_1_01.txt |
AC |
4 ms |
16640 KB |
subtask_1_02.txt |
AC |
20 ms |
20868 KB |
subtask_1_03.txt |
AC |
4 ms |
16640 KB |
subtask_1_04.txt |
AC |
4 ms |
16640 KB |
subtask_1_05.txt |
AC |
4 ms |
16640 KB |
subtask_1_06.txt |
AC |
5 ms |
16640 KB |
subtask_1_07.txt |
AC |
6 ms |
17024 KB |
subtask_1_08.txt |
AC |
22 ms |
20868 KB |
subtask_1_09.txt |
AC |
20 ms |
20868 KB |
subtask_1_10.txt |
AC |
20 ms |
20868 KB |
subtask_1_11.txt |
AC |
21 ms |
20868 KB |
subtask_1_12.txt |
AC |
20 ms |
20868 KB |
subtask_1_13.txt |
AC |
20 ms |
20868 KB |
subtask_1_14.txt |
AC |
20 ms |
20868 KB |
subtask_1_15.txt |
AC |
20 ms |
20868 KB |
subtask_1_16.txt |
AC |
20 ms |
20868 KB |
subtask_1_17.txt |
AC |
20 ms |
20868 KB |