結果

問題 No.59 鉄道の旅
ユーザー assy1028
提出日時 2015-03-25 14:47:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 2,007 bytes
コンパイル時間 1,482 ms
コンパイル使用メモリ 158,200 KB
実行使用メモリ 11,520 KB
最終ジャッジ日時 2024-12-24 20:35:29
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int solve(int, int)’:
main.cpp:92:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   92 |         scanf("%d", &w);
      |         ~~~~~^~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:114:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  114 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
typedef long long ll;
typedef pair<int, int> P;
typedef unsigned int uint;
typedef unsigned long long ull;
struct pairhash {
public:
template<typename T, typename U>
size_t operator()(const pair<T, U> &x) const {
size_t seed = hash<T>()(x.first);
return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
}
};
const int inf = 1000000009;
const double eps = 1e-8;
template<typename T, int max_n>
class BIT {
private:
T bit[max_n + 1];
int n;
public:
BIT(int _n = max_n) {
n = _n;
memset(bit, 0, sizeof(bit));
}
// [1, i]
T sum(int i) {
T s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
// [a, b]
T sum(int a, int b) {
return sum(b) - sum(a-1);
}
void add(int i, T x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
int lower_bound(T x) {
int lb = 0, ub = n;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
T v = sum(mid);
if (v < x) {
lb = mid;
} else {
ub = mid;
}
}
return ub;
}
int upper_bound(T x) {
int lb = 1, ub = n+1;
while (ub - lb > 1) {
int mid = (ub + lb) / 2;
T v = sum(mid);
if (v <= x) {
lb = mid;
} else {
ub = mid;
}
}
return ub;
}
};
int solve(int n, int k) {
const int buf = 1000001;
const int maxi = buf + buf;
BIT<int, maxi> bit;
for (int i = 0; i < n; i++) {
int w;
scanf("%d", &w);
if (w < 0) {
if (bit.sum(-w, -w) > 0) {
bit.add(-w, -1);
}
} else {
if (bit.sum(w, maxi) < k) {
bit.add(w, 1);
}
}
}
return bit.sum(maxi);
}
int main() {
/*
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(15);
*/
int n, k;
scanf("%d%d", &n, &k);
printf("%d\n", solve(n, k));
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0