QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#260815#1842. MathwsyearAC ✓61ms11356kbC++141.1kb2023-11-22 15:39:452023-11-22 15:39:45

Judging History

你现在查看的是最新测评结果

  • [2023-11-22 15:39:45]
  • 评测
  • 测评结果:AC
  • 用时:61ms
  • 内存:11356kb
  • [2023-11-22 15:39:45]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef dbg
#define D(...) fprintf(stderr, __VA_ARGS__)
#define DD(...) D(#__VA_ARGS__ " = "), debug_helper::debug(__VA_ARGS__), D("\n")
#include "C:\Users\wsyear\Desktop\OI\templates\debug.hpp"
#else
#define D(...) ((void)0)
#define DD(...) ((void)0)
#endif
#define rep(i, j, k) for (int i = (j); i <= (k); ++i)
#define per(i, j, k) for (int i = (j); i >= (k); --i)
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
using ll = long long;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

const int maxn = 1000010;
const int maxv = 1000000;

int n, a[maxn], cnt[maxn];

int main() {
  cin.tie(nullptr) -> ios::sync_with_stdio(false);
  cin >> n;
  rep (i, 1, n) cin >> a[i], cnt[a[i]]++;
  ll ans = 0;
  rep (x, 1, maxv) {
    int y = x + 1;
    while (true) {
      ll tmp = 1ll * y * y - 1ll * x * x;
      if (tmp > maxv) break;
      if (x == tmp) ans += 1ll * cnt[x] * (cnt[x] - 1);
      else ans += 1ll * cnt[x] * cnt[tmp];
      y++;
    }
  }
  cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 5596kb

input:

5
1 2 3 4 5

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 6ms
memory: 5344kb

input:

1
1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 6ms
memory: 5432kb

input:

5
6 4 7 3 5

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 6ms
memory: 5608kb

input:

50
89 2 3 86 81 59 29 26 28 8 48 5 6 95 54 91 17 83 4 36 15 43 92 70 30 37 23 96 39 80 9 90 49 82 33 71 61 38 99 50 65 47 78 45 68 7 25 42 13 57

output:

29

result:

ok 1 number(s): "29"

Test #5:

score: 0
Accepted
time: 6ms
memory: 5444kb

input:

1000
662 811 263 46 591 511 230 223 628 603 716 880 187 575 701 184 505 754 130 154 367 91 704 945 171 588 19 486 34 513 622 849 629 437 776 290 743 470 587 681 723 271 879 642 77 281 71 655 365 942 809 94 266 148 146 305 198 311 788 69 343 277 887 557 169 41 784 791 451 812 932 663 594 576 487 946 ...

output:

1750

result:

ok 1 number(s): "1750"

Test #6:

score: 0
Accepted
time: 7ms
memory: 5476kb

input:

10000
2246 4941 6031 8713 4705 3744 9374 9432 2502 7080 8851 5408 4724 8905 7565 1699 6660 8959 7798 2287 4610 8806 8128 451 1355 2111 8775 4903 7517 8983 8144 2578 9565 7332 3213 4943 6520 616 2559 5573 6391 7148 5121 8395 5618 8733 6132 3717 8549 9651 1291 9462 5941 2342 9625 398 3916 8586 4290 26...

output:

23368

result:

ok 1 number(s): "23368"

Test #7:

score: 0
Accepted
time: 11ms
memory: 5824kb

input:

100000
94437 49936 62522 1166 33452 90618 91436 81173 99242 37280 46125 44869 52811 45694 11550 29857 48941 56538 35057 40907 79925 70785 29658 19044 32804 11428 4127 92197 12680 61636 27200 56790 83389 80340 54411 15308 38952 78085 81397 37554 44186 33581 35662 73331 84991 32044 69012 82289 63495 6...

output:

291528

result:

ok 1 number(s): "291528"

Test #8:

score: 0
Accepted
time: 60ms
memory: 11200kb

input:

1000000
287979 230793 805881 397585 695359 701731 296206 140797 257828 646397 649020 775370 622178 482759 161855 499413 690372 463229 541524 906954 116709 106321 17736 555558 848745 804067 532778 605445 239082 752084 465207 248311 821443 697678 323802 224937 607056 905999 886110 635290 199168 451068...

output:

3492026

result:

ok 1 number(s): "3492026"

Test #9:

score: 0
Accepted
time: 3ms
memory: 6768kb

input:

1000
565029 359959 442072 749472 436627 555485 999899 922415 688282 1837 954923 117969 220561 401583 15736 11175 958620 494991 571014 578509 112950 719398 584928 609019 303702 314720 102291 123929 820634 58238 378539 87383 808107 690638 311089 86718 217615 410496 917686 56594 212682 997033 576713 36...

output:

4

result:

ok 1 number(s): "4"

Test #10:

score: 0
Accepted
time: 8ms
memory: 8624kb

input:

2000
934018 123504 948037 703617 111073 15546 15911 163976 468543 193910 726931 600453 733138 621635 783758 665702 245047 516540 973366 926404 185794 111170 240828 444820 241580 107050 107147 983125 983719 509772 744587 126168 497533 373596 725070 711935 110270 610693 852007 75812 415887 708945 4232...

output:

12

result:

ok 1 number(s): "12"

Test #11:

score: 0
Accepted
time: 4ms
memory: 7464kb

input:

5000
404514 156022 778654 104905 606286 153975 486040 552761 586695 488891 641333 481377 810874 486969 133738 774191 375113 853489 670894 302425 218622 559664 671453 845525 438566 841765 971373 185037 918208 681021 194600 257469 17258 263521 727182 298432 395201 136887 969041 654228 361441 627046 36...

output:

97

result:

ok 1 number(s): "97"

Test #12:

score: 0
Accepted
time: 61ms
memory: 11356kb

input:

999999
637199 962035 549540 306066 683256 982146 419109 444883 639652 682952 983960 112908 393066 739390 197927 265419 840349 863627 926843 969942 162339 70437 969985 352863 386976 103689 277001 339381 14016 688162 34317 386334 256660 305667 31010 674250 479909 432254 575034 378146 883525 914638 640...

output:

3492021

result:

ok 1 number(s): "3492021"

Test #13:

score: 0
Accepted
time: 33ms
memory: 9636kb

input:

500000
491404 372034 355751 236424 508721 594212 367998 857923 506665 274105 836508 706451 498983 63561 494579 661756 611470 898147 169460 873252 767279 299209 484156 951699 906903 455183 449838 666406 534596 812910 267104 446133 80361 558416 309233 990113 687484 401536 321061 44359 565110 116214 53...

output:

876495

result:

ok 1 number(s): "876495"

Test #14:

score: 0
Accepted
time: 34ms
memory: 9992kb

input:

700000
542043 824656 275019 725125 663633 76446 345569 722725 954407 523509 522864 810560 836717 585914 950832 423067 766556 542007 290389 949920 563105 792385 419462 719140 637288 987066 647103 422434 270323 698969 917723 134229 509697 26949 135145 293898 970665 87357 794642 784148 90355 759702 637...

output:

1715853

result:

ok 1 number(s): "1715853"

Test #15:

score: 0
Accepted
time: 38ms
memory: 10912kb

input:

800000
524345 430102 839374 837031 518646 137170 228764 779992 470062 883938 467978 602502 451096 51337 850637 266347 336074 197215 25085 732336 744893 529854 16702 607016 603093 789011 343254 814771 440652 351758 285877 976780 882697 954083 444762 162736 601098 143001 174386 895968 256584 63417 834...

output:

2242148

result:

ok 1 number(s): "2242148"

Test #16:

score: 0
Accepted
time: 55ms
memory: 10808kb

input:

900000
953834 992167 665073 283724 469347 930979 391834 432998 349663 183445 724052 954268 936923 380557 337472 200659 445465 51690 449268 892364 658706 640141 302696 512515 265145 924638 323657 390608 164941 923280 624434 351764 97956 710698 245590 438460 691426 105988 32249 556390 605876 262033 24...

output:

2824245

result:

ok 1 number(s): "2824245"