UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215259#2643. gcdThySecret0839ms30348kbC++112.3kb2024-11-27 20:46:292024-11-27 23:38:49

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define x first
#define y second
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)

inline void debug() { cerr << '\n'; }
template<typename Type, typename... Other>
inline void debug(const Type& x, const Other&... y) { cerr << x << ' '; debug(y...); }
#define DEBUG(a...) cerr << "[" << #a << "] = ", debug(a);

typedef long long LL;
typedef pair<int, int> PII;

const int N = 100010;
const int INF = 0x3f3f3f3f;

template<typename Type>
inline void read(Type &res)
{
    res = 0;
    int ch = getchar(), flag = 0;
    while (!isdigit(ch)) flag |= ch == '-', ch = getchar();
    while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();
    res = flag ? -res : res;
}
template<typename Type, typename... Other>
inline void read(Type &res, Other&... y) { read(res), read(y...); }

int n, q, a[N];
int stb[N][20], tot;
PII query[N];

void Init()
{
    for (int i = 1; i <= n; i ++) stb[i][0] = a[i];
    for (int k = 1; k < 20; k ++)
        for (int i = 1; i + (1 << k) - 1 <= n; i ++)
            stb[i][k] = __gcd(stb[i][k - 1], stb[i + (1 << k) - 1][k - 1]);
}

int Query(int l, int r)
{
    int k = __lg(r - l + 1);
    return __gcd(stb[l][k], stb[r - (1 << k) + 1][k]);
}

vector<PII> segs[N];
int ans[N];

unordered_map<int, int> mp;

signed main()
{
    read(n);
    for (int i = 1; i <= n; i ++) read(a[i]);
    read(q);
    for (int i = 1; i <= n; i ++)
    {
        read(query[i].x), query[i].y = i;
        if (!mp.count(query[i].x)) mp[query[i].x] = ++ tot;
    }
    Init();

    for (int i = 1; i <= n; i ++)
    {
        int idx = i;
        while (idx <= n)
        {
            int l = idx, r = n, res = -1;
            while (l <= r)
            {
                int mid = l + r >> 1;
                if (Query(i, mid) == Query(i, idx)) res = mid, l = mid + 1;
                else r = mid - 1;
            }
            if (mp.count(Query(i, res)))
                ans[mp[Query(i, res)]] += res - idx + 1;
            segs[i].emplace_back(idx, res), idx = res + 1;
        }
    }

    for (int i = 1; i <= n; i ++)
        cout << ans[mp[query[i].x]] << '\n';
    cout << '\n';

    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 5396kb

input:

1071
546 2340 8190 420 6300 1050 40950 25 23400 195 2340 630 195 40950 2184 504 525 130 2340 1800 39...

output:

31
569259
140
167
56
75
167
56
914
569259
31
151
22
97
167
75
914
569259
167
167
569259
569
140
56
5...

result:

wrong answer 1st lines differ - expected: '29', found: '31'

Test #2:

score: 0
Wrong Answer
time: 3ms
memory: 5856kb

input:

2878
728 50 420 4200 25 200 4 81900 546 195 11700 900 900 42 1092 520 6 36 6552 150 18200 130 585 28...

output:

167
412
487
92
2995
1068
167
199
92
487
92
448
121
282
448
4129789
92
412
167
4129789
4129789
1068
2...

result:

wrong answer 1st lines differ - expected: '183', found: '167'

Test #3:

score: 0
Wrong Answer
time: 5ms
memory: 5552kb

input:

1685
1365 225 40 9 3900 3900 2100 105 120 25 8 2184 2184 10 2100 23400 780 600 325 32760 4680 260 39...

output:

1413084
1344
198
48
806
1413084
1413084
806
83
279
198
179
83
706
93
93
83
1413084
93
241
706
241
70...

result:

wrong answer 1st lines differ - expected: '1412451', found: '1413084'

Test #4:

score: 0
Wrong Answer
time: 6ms
memory: 6016kb

input:

3492
1820 9100 45 8190 72 50 3276 260 14 8 24 65 910 5850 150 520 23400 520 700 2730 300 72 728 70 2...

output:

1670
1670
1606
2698
168
481
168
129
502
2698
540
1670
6083223
2698
168
184
1670
540
399
540
1670
502...

result:

wrong answer 1st lines differ - expected: '1954', found: '1670'

Test #5:

score: 0
Wrong Answer
time: 159ms
memory: 21772kb

input:

65614
4680 3900 2340 6825 5 1560 780 12600 75 140 156 50 3276 182 315 52 5460 40950 20475 14 78 2340...

output:

9328
1845
1845
9365
3524
3545
9365
2152338850
9365
9365
1845
6444
9376
3497
2152338850
9365
9376
283...

result:

wrong answer 1st lines differ - expected: '10574', found: '9328'

Test #6:

score: 0
Wrong Answer
time: 244ms
memory: 30348kb

input:

99228
11700 1400 35 1260 2520 975 56 100 18200 468 20 1560 450 900 36 468 9 4 56 650 195 3 468 4680 ...

output:

14711
2716
14113
43038
5190
14172
10229
10229
14711
5151
43038
14172
14113
14172
5151
5227
43038
271...

result:

wrong answer 1st lines differ - expected: '16046', found: '14711'

Test #7:

score: 0
Wrong Answer
time: 56ms
memory: 11748kb

input:

26035
39 900 315 1400 130 2600 7800 4095 234 36 200 25 312 1092 252 780 90 23400 1 4680 104 2 54600 ...

output:

11583
643
3970
3970
3741
3970
1326
3894
643
11109
3894
2509
1278
1326
3970
11109
3741
3970
2509
2509...

result:

wrong answer 1st lines differ - expected: '13708', found: '11583'

Test #8:

score: 0
Wrong Answer
time: 102ms
memory: 16024kb

input:

42842
468 325 390 1 120 150 6552 60 840 780 7800 126 35 140 40950 81900 6300 75 1050 210 6300 700 45...

output:

6080
2307
6273
917547776
2307
2201
917547776
4467
2201
2289
917547776
917547776
6475
2201
6273
6475
...

result:

wrong answer 1st lines differ - expected: '6626', found: '6080'

Test #9:

score: 0
Wrong Answer
time: 186ms
memory: 24576kb

input:

76456
8190 700 32760 27300 2100 24 3 126 1820 150 280 9100 104 3900 520 27300 65 1638 4095 273 450 1...

output:

11335
2922452954
11241
10811
7845
4025
32515
11335
4038
2027
4025
3944
34986
32515
2922452954
4025
7...

result:

wrong answer 1st lines differ - expected: '12422', found: '11335'

Test #10:

score: 0
Wrong Answer
time: 76ms
memory: 24652kb

input:

100000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

5000050000
5000050000
5000050000
5000050000
5000050000
5000050000
5000050000
5000050000
5000050000
5...

result:

wrong answer 100001st lines differ - expected: '5000050000', found: ''