提出 #21832371


ソースコード 拡げる

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<class V> struct BIT {
    BIT() {}  // [L, R)
    int NV;vector<V> bit;
    BIT(int n){ init(n); }
    void init(int n) { NV = 1; while (NV < n)NV *= 2; bit.resize(NV); clear(); }
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e&-e; return s; }
    void add(int e, V v) { e++; while (e <= NV) bit[e - 1] += v, e += e&-e; }
    int lower_bound(V val) { 
        V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
        if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
    }
    V get(int L, int R) {
        assert(0 <= L); assert(R <= NV); assert(L <= R);
        V res = 0; if(R) res += operator[](R - 1); if (L) res -= operator[](L - 1);return res;
    }
    void clear() { rep(i, 0, NV) bit[i] = 0; }
	void update(int e, V v) { add(e, v - get(e, e + 1)); }
};
vector<int> compress1(int *v, int n) {
    vector<int> dic;
    rep(i, 0, n) dic.push_back(v[i]);
    sort(all(dic));
    dic.erase(unique(all(dic)), dic.end());
    rep(i, 0, n) v[i] = lower_bound(all(dic), v[i]) - dic.begin();
    return dic;
}
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, Q, T[201010], X[201010], Y[201010];
int A[201010], B[201010];
BIT<ll> Acnt(201010), Bcnt(201010);
BIT<ll> Atot(201010), Btot(201010);
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> Q;
    rep(i, 0, Q) cin >> T[i] >> X[i] >> Y[i];

    auto ZY = compress1(Y, Q + 1);
    Acnt.add(0, N);
    Bcnt.add(0, M);

    ll ans = 0;
    rep(q, 0, Q) {
        if (T[q] == 1) {
            int x = X[q] - 1;
            int y = Y[q];
            ans -= Bcnt.get(0, A[x] + 1) * ZY[A[x]];
            ans -= Btot.get(A[x] + 1, 201010);

            Acnt.add(A[x], -1);
            Atot.add(A[x], -ZY[A[x]]);

            A[x] = y;

            ans += Bcnt.get(0, A[x] + 1) * ZY[A[x]];
            ans += Btot.get(A[x] + 1, 201010);

            Acnt.add(A[x], 1);
            Atot.add(A[x], ZY[A[x]]);
        }
        else {

            int x = X[q] - 1;
            int y = Y[q];
            ans -= Acnt.get(0, B[x] + 1) * ZY[B[x]];
            ans -= Atot.get(B[x] + 1, 201010);

            Bcnt.add(B[x], -1);
            Btot.add(B[x], -ZY[B[x]]);

            B[x] = y;

            ans += Acnt.get(0, B[x] + 1) * ZY[B[x]];
            ans += Atot.get(B[x] + 1, 201010);

            Bcnt.add(B[x], 1);
            Btot.add(B[x], ZY[B[x]]);
        }
        printf("%lld\n", ans);
    }
}





提出情報

提出日時
問題 F - Max Matrix
ユーザ hamayanhamayan
言語 C++ (GCC 9.2.1)
得点 600
コード長 3835 Byte
結果 AC
実行時間 180 ms
メモリ 17112 KiB

コンパイルエラー

./Main.cpp: In member function ‘int BIT<V>::lower_bound(V)’:
./Main.cpp:22:9: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
   22 |         if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
      |         ^~
./Main.cpp:22:76: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
   22 |         if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
      |                                                                            ^~~~~~
./Main.cpp:21:35: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
   21 |         V tv = 0; int i, ent = 0; for (i = NV - 1; i >= 0; i--)
      |                                   ^~~
./Main.cpp:22:76: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
   22 |         if(tv+bit[ent+(1<<i)-1]<=val)tv+=bit[ent+(1<<i)-1],ent += (1 << i);return ent;
      |                                                                            ^~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 39
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All manual_00.txt, manual_01.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_biased_00.txt, random_biased_01.txt, random_biased_02.txt, random_biased_03.txt, random_biased_04.txt, random_biased_05.txt, random_biased_06.txt, random_biased_07.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
manual_00.txt AC 16 ms 11236 KiB
manual_01.txt AC 13 ms 11128 KiB
random_00.txt AC 180 ms 15580 KiB
random_01.txt AC 146 ms 15664 KiB
random_02.txt AC 155 ms 15620 KiB
random_03.txt AC 157 ms 15640 KiB
random_04.txt AC 13 ms 11068 KiB
random_05.txt AC 14 ms 11128 KiB
random_06.txt AC 43 ms 12108 KiB
random_07.txt AC 79 ms 13000 KiB
random_08.txt AC 32 ms 11996 KiB
random_09.txt AC 101 ms 14056 KiB
random_10.txt AC 48 ms 14012 KiB
random_11.txt AC 128 ms 15848 KiB
random_12.txt AC 76 ms 14628 KiB
random_13.txt AC 142 ms 16468 KiB
random_14.txt AC 85 ms 14880 KiB
random_15.txt AC 132 ms 15964 KiB
random_16.txt AC 94 ms 14976 KiB
random_17.txt AC 17 ms 13156 KiB
random_18.txt AC 81 ms 13856 KiB
random_19.txt AC 151 ms 16084 KiB
random_20.txt AC 94 ms 14568 KiB
random_21.txt AC 42 ms 12632 KiB
random_22.txt AC 119 ms 14360 KiB
random_23.txt AC 59 ms 13404 KiB
random_24.txt AC 113 ms 15180 KiB
random_25.txt AC 60 ms 12924 KiB
random_biased_00.txt AC 162 ms 17048 KiB
random_biased_01.txt AC 153 ms 17088 KiB
random_biased_02.txt AC 158 ms 17080 KiB
random_biased_03.txt AC 150 ms 17112 KiB
random_biased_04.txt AC 92 ms 13916 KiB
random_biased_05.txt AC 17 ms 12196 KiB
random_biased_06.txt AC 104 ms 14916 KiB
random_biased_07.txt AC 141 ms 15884 KiB
sample_01.txt AC 12 ms 11008 KiB
sample_02.txt AC 10 ms 11208 KiB
sample_03.txt AC 13 ms 11132 KiB