답안 #804327

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
804327 2023-08-03T08:02:55 Z 이동현(#10103) Vera and Modern Art (CCO17_art) C++17
0 / 25
143 ms 8184 KB
#include <bits/stdc++.h>
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
using namespace std;

unordered_map<signed int, int> srt[32][32];
unordered_map<signed int, int> saveans;

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    auto len = [&](signed int x){
        return 32 - __builtin_clz(x);
    };

    int n, q;
    cin >> n >> q;
    signed int A = 998244353;
    signed int B = (int)1e9 + 9;
    for(int i = 0; i < n; ++i){
        signed long long inx, iny;
        int v;
        cin >> inx >> iny >> v;
        signed int x = inx, y = iny;
        if(inx <= (int)1e9 && iny <= (int)1e9)
            srt[len(x) - 1][len(y) - 1][A * x + B * y] += v;
    }

    for(int rep = 0; rep < q; ++rep){
        signed int x, y;
        cin >> x >> y;

        auto q = saveans.find(A * x + B * y);
        if(q != saveans.end()){
            cout << q->second << '\n';
            continue;
        }
        
        int ans = 0;
        for(int i = 0; (1ll << i) <= x; ++i){
            for(int j = 0; (1ll << j) <= y; ++j){
                if(!(int)srt[i][j].size()) continue;
                signed int px = x % (1ll << i) + (1ll << i);
                signed int py = y % (1ll << j) + (1ll << j);

                auto p = srt[i][j].find(A * px + B * py);
                if(p != srt[i][j].end()){
                    ans += p->second;
                }
            }
        }

        cout << ans << '\n';

        saveans[A * x + B * y] = ans;
    }
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 54 ms 752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 143 ms 8184 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -