提出 #72525004
ソースコード 拡げる
#include <iostream>
using namespace std;
struct BIT {
vector<long long> bit;
int n;
BIT(int n) : n(n), bit(n + 2, 0) {}
void update(int i, long long val) {
for (; i <= n; i += i & -i)
bit[i] += val;
}
long long query(int i) {
long long res = 0;
for (; i > 0; i -= i & -i)
res += bit[i];
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N;
string S;
cin >> N >> S;
vector<int> x(N);
for (int i = 0; i < N; i++) {
if (S[i] == 'A')
x[i] = 1;
else if (S[i] == 'B')
x[i] = -1;
else
x[i] = 0;
}
vector<long long> prefix(N + 1, 0);
for (int i = 0; i < N; i++)
prefix[i + 1] = prefix[i] + x[i];
vector<long long> all = prefix;
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
auto getIndex = [&](long long val) {
return lower_bound(all.begin(), all.end(), val) - all.begin() + 1;
};
BIT bit(all.size());
long long ans = 0;
for (int i = 0; i <= N; i++) {
int idx = getIndex(prefix[i]);
if (i > 0)
ans += bit.query(idx - 1);
bit.update(idx, 1);
}
cout << ans << "\n";
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - A > B substring |
| ユーザ | adityagrg023 |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 0 |
| コード長 | 1371 Byte |
| 結果 | CE |
コンパイルエラー
./Main.cpp:5:21: error: wrong number of template arguments (1, should be 2)
5 | vector<long long> bit;
| ^
In file included from /opt/atcoder/gcc/include/c++/15.2.0/ostream:44,
from /opt/atcoder/gcc/include/c++/15.2.0/iostream:43,
from ./Main.cpp:1:
/opt/atcoder/gcc/include/c++/15.2.0/format:3054:36: note: provided for 'template<class, class> class std::vector'
3054 | template<typename, typename> class vector;
| ^~~~~~
./Main.cpp: In constructor 'BIT::BIT(int)':
./Main.cpp:6:9: warning: 'BIT::n' will be initialized after [-Wreorder]
6 | int n;
| ^
./Main.cpp:5:23: warning: 'int BIT::bit' [-Wreorder]
5 | vector<long long> bit;
| ^~~
./Main.cpp:7:5: warning: when initialized here [-Wreorder]
7 | BIT(int n) : n(n), bit(n + 2, 0) {}
| ^~~
./Main.cpp:7:24: error: expression list treated as compound expression in mem-initializer [-fpermissive]
7 | BIT(int n) : n(n), bit(n + 2, 0) {}
| ^~~~~~~~~~~~~
./Main.cpp:7:30: warning: left operand of comma operator has no effect [-Wunused-value]
7 | BIT(int n) : n(n), bit(n + 2, 0) {}
| ~~^~~
./Main.cpp: In member function 'void BIT::update(int, long long int)':
./Main.cpp:10:16: error: invalid types 'int[int]' for array subscript
10 | bit[i] += val;
| ^
./Main.cpp: In member function 'long long int BIT::query(int)':
./Main.cpp:15:23: error: invalid types 'int[int]' for array subscript
15 | res += bit[i];
| ^
./Main.cpp: In function 'int main()':
./Main.cpp:26:15: error: wrong number of template arguments (1, should be 2)
26 | vector<int> x(N);
| ^
/opt/atcoder/gcc/include/c++/15.2.0/format:3054:36: note: provided for 'template<class, class> class std::vector'
3054 | template<typename, typename> class vector;
| ^~~~~~
./Main.cpp:29:14: error: invalid types 'int[int]' for array subscript
29 | x[i] = 1;
| ^
./Main.cpp:31:14: error: invalid types 'int[int]' for array subscript
31 | x[i] = -1;
| ^
./Main.cpp:33:14: error: invalid types 'int[int]' for array subscript
33 | x[i] = 0;
| ^
./Main.cpp:35:21: error: wrong number of template arguments (1, should be 2)
35 | vector<long long> prefix(N + 1, 0);
| ^
/opt/atcoder/gcc/include/c++/15.2.0/format:3054:36: note: provided for 'template<class, class> class std::vector'
3054 | template<typename, typename> class vector;
| ^~~~~~
./Main.cpp:35:38: error: expression list treated as compound expression in initializer [-fpermissive]
35 | vector<long long> prefix(N + 1, 0);
| ^
./Main.cpp:35:32: warning: left operand of comma operator has no effect [-Wunused-value]
35 | vector<long long> prefix(N + 1, 0);
| ~~^~~
./Main.cpp:37:15: error: invalid types 'int[int]' for array subscript
37 | prefix[i + 1] = prefix[i] + x[i];
| ^
./Main.cpp:37:31: error: invalid types 'int[int]' for array subscript
37 | prefix[i + 1] = prefix[i] + x[i];
| ^
./Main.cpp:37:38: error: invalid types 'int[int]' for array subscript
37 | prefix[i + 1] = prefix[i] + x[i];
| ^
./Main.cpp:38:21: error: wrong number of template arguments (1, should be 2)
38 | vector<long long> all = prefix;
| ^
/opt/atcoder/gcc/include/c++/15.2.0/format:3054:36: note: provided for 'template<class, class> class std::vector'
3054 | template<typename, typename> class vector;
| ^~~~~~
./Main.cpp:39:14: error: request for member 'begin' in 'all', which is of non-class type 'int'
39 | sort(all.begin(), all.end());
| ^~~~~
./Main.cpp:39:27: error: request for member 'end' in 'all', which is of non-class type 'int'
39 | sort(all.begin(), all.end());
| ^~~
./Main.cpp:40:9: error: request for member 'erase' in 'all', which is of non-class type 'int'
40 | all.erase(unique(all.begin(), all.end()), all.end());
| ^~~~~
./Main.cpp:40:26: error: request for member 'begin' in 'all', which is of non-class type 'int'
40 | all.erase(unique(all.begin(), all.end()), all.end());
| ^~~~~
./Main.cpp:40:39: error: request for member 'end' in 'all', which is of non-class type 'int'
40 | all.erase(unique(all.begin(), all.end()), all.end());
| ^~~
./Main.cpp:40:51: error: request for member 'end' in 'all', which is of non-class type 'int'
40 | all.erase(unique(all.begin(), all.end()), all.end());
| ^~~
./Main.cpp: In lambda function:
./Main.cpp:42:32: error: request for member 'begin' in 'all', which is of non-class type 'int'
42 | return lower_bound(all.begin(), all.end(), val) - all.begin() + 1;
| ^~~~~
./Main.cpp:42:45: error: request for member 'end' in 'all', which is of non-class type 'int'
42 | return lower_bound(all.begin(), all.end(), val) - all.begin() + 1;
| ^~~
./Main.cpp:42:63: error: request for member 'begin' in 'all', which is of non-class type 'int'
42 | return lower_bound(all.begin(), all.end(), val) - all.begin() + 1;
| ^~~~~
./Main.cpp: In function 'int main()':
./Main.cpp:44:17: error: request for member 'size' in 'all', which is of non-class type 'int'
44 | BIT bit(all.size());
| ^~~~
./Main.cpp:47:34: error: invalid types 'int[int]' for array subscript
47 | int idx = getIndex(prefix[i]);
| ^