QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#808073 | #9853. Easy String Problem | BreakPlus | WA | 31ms | 7292kb | C++14 | 1.7kb | 2024-12-10 16:52:36 | 2024-12-10 16:52:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define mkp make_pair
#define pb emplace_back
#define popcnt __builtin_popcountll
const ll mod = 998244353;
inline ll read(){
ll x=0, f=1; char ch=getchar();
while(ch<'0' || ch>'9') { if(ch=='-') f=-1; ch=getchar(); }
while(ch>='0' && ch<='9') x=x*10+ch-'0', ch=getchar();
return x*f;
}
inline int lg2(int x){ return 31^__builtin_clz(x); }
inline ll lg2(ll x){ return 63^__builtin_clzll(x); }
inline ll qpow(ll a,ll b){
ll ans=1, base=a;
while(b){
if(b&1) ans=ans*base%mod;
base=base*base%mod; b>>=1;
}
return ans;
}
void init(){ }
const int B = 350;
int n,a[100005],bl[100005],s[100005],t[100005];
ll ans; ll ret[100005];
struct Node{
int l,r,id;
}q[100005];
void upds(int x, int v){ s[x] += v; ans += 1ll*v*t[x]; }
void updt(int x, int v){ t[x] += v; ans += 1ll*v*s[x]; }
bool operator< (Node A, Node B){
if(bl[A.l] == bl[B.l]) return A.r<B.r;
else return bl[A.l] < bl[B.l];
}
void procedure(){
n=read();
for(int i=1;i<=n;i++){
a[i]=read(); bl[i]=(i-1)/B+1;
}
int Q=read();
for(int i=1;i<=Q;i++)
q[i] = (Node){read(),read(),i};
sort(q+1, q+Q+1);
int cl=1, cr=n;
for(int i=1;i<=Q;i++){
while(cl<q[i].l) upds(a[cl++], 1);
while(cl>q[i].l) upds(a[--cl], -1);
while(cr>q[i].r) updt(a[cr--], 1);
while(cr<q[i].r) updt(a[++cr], -1);
ret[q[i].id] = cl*(n-cr+1)-ans;
}
for(int i=1;i<=Q;i++) printf("%d\n", ret[i]);
}
int main(){
#ifdef LOCAL
assert(freopen("input.txt","r",stdin));
assert(freopen("output.txt","w",stdout));
#endif
ll T=1;
init();
while(T--) procedure();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3988kb
input:
4 1 2 3 1 6 1 1 3 3 2 3 2 4 1 3 1 4
output:
4 5 3 2 2 1
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3880kb
input:
100 3 7 9 13 13 10 13 5 12 17 6 1 18 25 20 17 2 18 20 9 21 14 13 15 19 7 10 7 10 17 13 24 13 24 14 17 23 23 5 14 16 23 26 7 26 24 18 5 12 10 1 4 13 10 14 3 22 26 21 3 20 3 23 3 14 18 23 20 14 22 18 2 20 11 8 23 17 5 21 7 15 11 8 24 13 20 10 7 15 3 21 17 10 23 14 9 26 16 5 9 100 96 100 43 56 16 24 43...
output:
96 1855 1185 2347 1812 1669 1756 1921 539 1276 2086 1810 1664 2075 1691 1864 461 1655 654 187 2167 2224 2019 273 1873 1328 1282 1474 918 481 456 2018 2014 2256 452 2028 1655 1879 100 1312 1894 1428 2118 1773 1602 1752 1772 2246 2129 517 1694 325 591 885 1882 287 619 796 1965 1845 1035 1656 1725 801 ...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
100 42 68 35 1 70 25 79 59 63 65 6 46 82 28 62 92 96 43 28 37 92 5 3 54 93 83 22 17 19 96 48 27 72 39 70 13 68 100 36 95 4 12 23 34 74 65 42 12 54 69 48 45 63 58 38 60 24 42 30 79 17 36 91 43 89 7 41 43 65 49 47 6 91 30 71 51 7 2 94 49 30 24 85 55 57 41 67 77 32 9 45 40 27 24 38 39 19 83 30 42 100 3...
output:
2092 2104 476 1313 1540 1615 1836 1477 1546 288 1204 2029 2115 2281 2127 2533 2293 2257 730 682 2074 2359 2103 823 1550 1643 653 1096 99 2062 882 1712 2384 377 290 634 1932 285 2093 1916 1217 2040 1393 92 1835 1986 2384 730 904 1152 843 2287 91 1487 99 1687 2102 797 472 648 1668 1234 2530 1991 1122 ...
result:
ok 100 numbers
Test #4:
score: 0
Accepted
time: 1ms
memory: 5896kb
input:
100 51 5 23 9 91 93 14 6 39 30 36 49 17 95 15 59 96 68 54 75 50 46 28 82 73 45 95 35 94 42 20 90 64 68 33 13 56 81 44 36 73 12 50 65 7 81 76 94 68 86 48 69 54 65 91 32 1 68 6 59 95 91 39 14 35 48 5 63 20 35 95 64 46 25 84 61 13 47 63 25 76 43 57 45 55 14 63 89 61 10 54 10 20 57 16 75 74 67 69 64 100...
output:
1880 2070 1321 2271 776 833 749 2406 2116 1208 939 363 2277 190 1928 1525 383 2118 1365 833 2002 959 2335 1610 863 1464 833 1175 2521 2320 1709 2106 691 1987 1468 1525 1848 184 1058 1084 1516 1744 1031 99 1320 369 2447 2047 983 2099 1950 434 2209 2094 2054 1993 2241 2215 1997 1679 98 2142 1884 2215 ...
result:
ok 100 numbers
Test #5:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
1000 42 468 335 501 170 725 479 359 963 465 706 146 282 828 962 492 996 943 828 437 392 605 903 154 293 383 422 717 719 896 448 727 772 539 870 913 668 300 36 895 704 812 323 334 674 665 142 712 254 869 548 645 663 758 38 860 724 742 530 779 317 36 191 843 289 107 41 943 265 649 447 806 891 730 371 ...
output:
216894 215359 241961 138802 246872 217900 214631 222775 21473 198360 212431 85704 109259 188552 243956 149952 216687 78014 248931 118246 100745 77269 205516 3985 51700 201164 249181 114060 243058 197913 2986 194731 181210 69780 219569 247138 247442 133414 125113 36363 223344 235530 89205 207220 1987...
result:
ok 1000 numbers
Test #6:
score: 0
Accepted
time: 1ms
memory: 3836kb
input:
1000 170 859 536 817 42 85 420 711 504 610 849 513 778 769 896 984 464 647 970 251 539 28 113 902 686 262 674 86 116 149 126 139 147 511 609 767 391 564 50 62 697 604 981 942 569 664 285 665 242 935 854 609 749 802 753 692 769 962 953 512 738 920 479 153 23 589 929 552 113 659 552 478 352 548 113 60...
output:
133756 212374 244573 237234 223728 207907 242738 100453 95923 220564 230508 239573 141124 41156 241964 240751 109146 89906 246009 142768 216030 26252 239148 20501 181713 215108 243996 241152 235725 31852 245663 239175 150449 150704 129395 211689 170773 186079 245716 137651 247713 240964 37447 179304...
result:
ok 1000 numbers
Test #7:
score: 0
Accepted
time: 23ms
memory: 6532kb
input:
100000 23 16 26 1 10 5 9 8 11 3 26 18 1 26 20 7 23 10 5 25 11 22 21 13 23 15 14 20 16 5 1 6 17 12 12 2 7 6 8 23 19 6 24 24 6 3 7 17 20 7 7 15 21 14 7 20 21 11 20 22 21 19 26 14 11 19 7 22 4 6 9 22 10 22 13 19 24 18 16 12 15 1 12 13 14 6 24 23 11 11 15 2 8 20 25 25 23 20 24 22 11 11 15 3 8 7 12 7 8 6...
output:
1595515722 1546937649 1922022743 1628223414 1667083008 1469008421 1732606197 1511295965 1902115405 1492058814 1364988533 1501865960 1266798327 1349948880 1601724403 1544137060 302722455 450210851 146312419 2046939837 369445091 345494836 1172133510 1941450403 1160240183 1091275914 266472316 126593146...
result:
ok 100000 numbers
Test #8:
score: 0
Accepted
time: 31ms
memory: 6528kb
input:
100000 13 15 24 24 12 7 7 26 2 18 1 19 18 26 2 4 21 22 6 13 25 12 9 23 14 20 9 12 22 7 24 4 8 24 9 23 22 7 5 4 2 11 14 21 6 5 19 10 13 14 7 24 26 22 2 12 12 25 16 22 15 16 16 10 23 7 1 10 19 13 6 2 9 25 17 18 24 23 8 9 7 18 12 18 15 13 22 13 1 26 12 20 15 2 13 14 5 26 9 17 21 19 15 18 17 15 25 10 18...
output:
1477651739 1787671227 1477666442 476432181 1199623379 674874991 1813784048 1388950405 653591503 969329474 312981042 1393371994 606900835 798554668 1878800006 1930377777 1246510858 46227907 1941525007 2023925793 1890797999 528235933 192360113 1566312494 1175713437 642653112 1762500974 1074076848 1769...
result:
ok 100000 numbers
Test #9:
score: -100
Wrong Answer
time: 30ms
memory: 7292kb
input:
100000 8242 2948 6332 8921 7587 1937 6358 3847 4311 2192 595 482 3313 572 7604 7206 9636 3786 3478 505 3304 929 2759 3383 2272 9179 2710 5103 2585 1868 3611 395 5717 2275 4455 9397 7081 6639 9484 3049 1220 5907 6640 2630 6161 5869 7199 4153 3326 7956 3839 5659 8430 6352 5336 5545 9756 3870 3251 7029...
output:
1895850807 798168077 1234574101 900147002 2030327600 344132552 1724012633 1181873825 1861179818 805040308 1964666227 1611692482 905775043 564459593 2105268459 582789708 406684522 1298444734 2053817730 1498408492 1834701643 306005491 2140599273 1010175646 972958177 438954333 1869023520 2071932132 282...
result:
wrong answer 43rd numbers differ - expected: '2149859927', found: '-2145107369'