結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-25 11:03:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,535 bytes |
| コンパイル時間 | 870 ms |
| コンパイル使用メモリ | 91,052 KB |
| 最終ジャッジ日時 | 2024-11-14 22:00:15 |
| 合計ジャッジ時間 | 2,426 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:46:30: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
46 | scanf("%d", &v[i][j]);
| ^
main.cpp:48:16: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
48 | if(v[i][0] == 0){
| ^
main.cpp:49:32: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
49 | z.emplace_back(v[i][1]);
| ^
main.cpp:57:16: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
57 | if(v[i][0] == 0){
| ^
main.cpp:58:54: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
58 | S.add(lower_bound(z.begin(),z.end(), v[i][1]) - z.begin() + 1, v[i][2]);
| ^
main.cpp:58:80: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::array<int, 3> >, std::array<int, 3> >::value_type' {aka 'std::array<int, 3>'} and 'int')
58 | S.add(lower_bound(z.begin(),z.end(), v[i][1]) - z.begin() + 1, v[i][2]);
| ^
main.cpp:60:56: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::a
ソースコード
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
#include <limits>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template<class T>
class BIT {
vector<T> bit;
public:
BIT(int n): bit(vector<T>(n+1, 0)){}
T sum(int k){
T ret = 0;
for (++k; k > 0; k -= (k & -k)) ret += bit[k];
return ret;
}
void add(int k, T x){
for (++k; k < bit.size(); k += (k & -k)) bit[k] += x;
}
};
int main() {
int n;
cin >> n;
vector<array<int, 3>> v(n);
vector<int> z;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 3; ++j) {
scanf("%d", &v[i][j]);
}
if(v[i][0] == 0){
z.emplace_back(v[i][1]);
}
}
sort(z.begin(), z.end());
z.erase(unique(z.begin(), z.end()), z.end());
BIT<int> S(z.size()+1);
ll ans = 0;
for (int i = 0; i < n; ++i) {
if(v[i][0] == 0){
S.add(lower_bound(z.begin(),z.end(), v[i][1]) - z.begin() + 1, v[i][2]);
}else {
int l = lower_bound(z.begin(),z.end(), v[i][1]) - z.begin();
int r = upper_bound(z.begin(),z.end(), v[i][2]) - z.begin();
ans += S.sum(r) - S.sum(l);
}
}
cout << ans << "\n";
return 0;
}