답안 #804463

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

unordered_map<signed long long, int> srt[70][70];
unordered_map<signed long long, int> saveans;

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

    auto len = [&](signed long long x){
        return 64 - __builtin_clzll(x);
    };

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


    for(int rep = 0; rep < q; ++rep){
        signed long long 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 long long px = x % (1ll << i) + (1ll << i);
                signed long long 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 596 KB Output is correct
2 Correct 7 ms 740 KB Output is correct
3 Correct 8 ms 744 KB Output is correct
4 Correct 107 ms 884 KB Output is correct
5 Correct 112 ms 972 KB Output is correct
6 Correct 27 ms 868 KB Output is correct
7 Correct 27 ms 896 KB Output is correct
8 Correct 27 ms 896 KB Output is correct
9 Correct 25 ms 896 KB Output is correct
10 Correct 27 ms 868 KB Output is correct
11 Correct 28 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 928 ms 19876 KB Output is correct
2 Correct 942 ms 20040 KB Output is correct
3 Correct 2248 ms 19124 KB Output is correct
4 Correct 1996 ms 19196 KB Output is correct
5 Correct 833 ms 18996 KB Output is correct
6 Correct 833 ms 18980 KB Output is correct
7 Correct 781 ms 18948 KB Output is correct
8 Correct 895 ms 19016 KB Output is correct
9 Correct 822 ms 18940 KB Output is correct
10 Correct 828 ms 19008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 146 ms 8712 KB Output is correct
3 Correct 147 ms 8576 KB Output is correct
4 Execution timed out 4062 ms 8536 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 7 ms 740 KB Output is correct
3 Correct 8 ms 744 KB Output is correct
4 Correct 107 ms 884 KB Output is correct
5 Correct 112 ms 972 KB Output is correct
6 Correct 27 ms 868 KB Output is correct
7 Correct 27 ms 896 KB Output is correct
8 Correct 27 ms 896 KB Output is correct
9 Correct 25 ms 896 KB Output is correct
10 Correct 27 ms 868 KB Output is correct
11 Correct 28 ms 860 KB Output is correct
12 Correct 928 ms 19876 KB Output is correct
13 Correct 942 ms 20040 KB Output is correct
14 Correct 2248 ms 19124 KB Output is correct
15 Correct 1996 ms 19196 KB Output is correct
16 Correct 833 ms 18996 KB Output is correct
17 Correct 833 ms 18980 KB Output is correct
18 Correct 781 ms 18948 KB Output is correct
19 Correct 895 ms 19016 KB Output is correct
20 Correct 822 ms 18940 KB Output is correct
21 Correct 828 ms 19008 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 146 ms 8712 KB Output is correct
24 Correct 147 ms 8576 KB Output is correct
25 Execution timed out 4062 ms 8536 KB Time limit exceeded
26 Halted 0 ms 0 KB -