QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#620656#7441. rpxleqxqN_z_39 632ms67528kbC++207.7kb2024-10-07 20:05:412024-10-07 20:05:42

Judging History

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

  • [2024-10-07 20:05:42]
  • 评测
  • 测评结果:39
  • 用时:632ms
  • 内存:67528kb
  • [2024-10-07 20:05:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
struct time_helper{
#ifdef LOCAL
clock_t time_last;time_helper(){time_last=clock();}void test(){auto time_now=clock();std::cerr<<"time:"<<1.*(time_now-time_last)/CLOCKS_PER_SEC<<";all_time:"<<1.*time_now/CLOCKS_PER_SEC<<std::endl;time_last=time_now;}~time_helper(){test();}
#else
void test(){}
#endif
}time_helper;
#ifdef LOCAL
#include"dbg.h"
#else
#define dbg(...) (__VA_ARGS__)
#endif
namespace Fread{const int SIZE=1<<16;char buf[SIZE],*S,*T;inline char getchar(){if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return'\n';}return *S++;}}namespace Fwrite{const int SIZE=1<<16;char buf[SIZE],*S=buf,*T=buf+SIZE;inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}inline void putchar(char c){*S++=c;if(S==T)flush();}struct NTR{~NTR(){flush();}}ztr;}
#define getchar Fread::getchar
#define putchar Fwrite::putchar
int print_precision=10;bool print_T_endl=1;char print_between=' ';
template<typename T>struct is_char{static constexpr bool value=(std::is_same<T,char>::value||std::is_same<T,signed char>::value||std::is_same<T,unsigned char>::value);};template<typename T>struct is_integral_ex{static constexpr bool value=(std::is_integral<T>::value||std::is_same<T,__int128>::value)&&!is_char<T>::value;};template<typename T>struct is_floating_point_ex{static constexpr bool value=std::is_floating_point<T>::value||std::is_same<T,__float128>::value;};namespace Fastio{struct Reader;struct Writer;template<size_t id>struct read_tuple{template<typename...T>static void read(Reader&stream,std::tuple<T...>&x){read_tuple<id-1>::read(stream,x);stream>>get<id-1>(x);}};template<>struct read_tuple<0>{template<typename...T>static void read([[maybe_unused]]Reader&stream,[[maybe_unused]]std::tuple<T...>&x){}};template<size_t id>struct print_tuple{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){print_tuple<id-1>::print(stream,x);putchar(print_between);stream<<get<id-1>(x);}};template<>struct print_tuple<1>{template<typename...T>static void print(Writer&stream,const std::tuple<T...>&x){stream<<get<0>(x);}};template<>struct print_tuple<0>{template<typename...T>static void print([[maybe_unused]]Writer&stream,[[maybe_unused]]const std::tuple<T...>&x){}};
struct Reader{template<typename T>typename std::enable_if_t<std::is_class<T>::value,Reader&>operator>>(T&x){for(auto &y:x)*this>>y;return *this;}template<typename...T>Reader&operator>>(std::tuple<T...>&x){read_tuple<sizeof...(T)>::read(*this,x);return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1;while(c<'0'||c>'9'){if(c=='-')f*=-1;c=getchar();}x=0;while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}x*=f;return *this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Reader&>operator>>(T&x){char c=getchar();short f=1,s=0;x=0;T t=0;while((c<'0'||c>'9')&&c!='.'){if(c=='-')f*=-1;c=getchar();}while(c>='0'&&c<='9'&&c!='.')x=x*10+(c^48),c=getchar();if(c=='.')c=getchar();else return x*=f,*this;while(c>='0'&&c<='9')t=t*10+(c^48),s++,c=getchar();while(s--)t/=10.0;x=(x+t)*f;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Reader&>operator>>(T&c){c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();return *this;}Reader&operator>>(char*str){int len=0;char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str[len++]=c,c=getchar();str[len]='\0';return*this;}template<typename T1,typename T2>Reader&operator>>(std::pair<T1,T2>&x){*this>>x.first>>x.second;return *this;}Reader&operator>>(std::string&str){str.clear();char c=getchar();while(c=='\n'||c==' '||c=='\r')c=getchar();while(c!='\n'&&c!=' '&&c!='\r')str.push_back(c),c=getchar();return*this;}Reader(){}}cin;const char endl='\n';
struct Writer{typedef __int128 mxdouble;template<typename T>typename std::enable_if_t<std::is_class<T>::value,Writer&>operator<<(const T&x){for(auto q:x){*this<<q;if(!is_class<decltype(q)>::value)*this<<print_between;}if(!is_class<typename T::value_type>::value&&print_T_endl)*this<<'\n';return *this;}template<typename...T>Writer&operator<<(const std::tuple<T...>&x){print_tuple<sizeof...(T)>::print(*this,x);if(print_T_endl)*this<<'\n';return *this;}template<typename T>typename std::enable_if_t<is_integral_ex<T>::value,Writer&>operator<<(T x){if(x==0)return putchar('0'),*this;if(x<0)putchar('-'),x=-x;static int sta[45];int top=0;while(x)sta[++top]=x%10,x/=10;while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_floating_point_ex<T>::value,Writer&>operator<<(T x){if(x<0)putchar('-'),x=-x;x+=pow(10,-print_precision)/2;mxdouble _=x;x-=(T)_;static int sta[45];int top=0;while(_)sta[++top]=_%10,_/=10;if(!top)putchar('0');while(top)putchar(sta[top]+'0'),--top;putchar('.');for(int i=0;i<print_precision;i++)x*=10;_=x;while(_)sta[++top]=_%10,_/=10;for(int i=0;i<print_precision-top;i++)putchar('0');while(top)putchar(sta[top]+'0'),--top;return*this;}template<typename T>typename std::enable_if_t<is_char<T>::value,Writer&>operator<<(const T&c){putchar(c);return*this;}Writer&operator<<(char*str){int cur=0;while(str[cur])putchar(str[cur++]);return *this;}Writer&operator<<(const char*str){int cur=0;while(str[cur])putchar(str[cur++]);return*this;}template<typename T1,typename T2>Writer&operator<<(const std::pair<T1,T2>&x){*this<<x.first<<print_between<<x.second;if(print_T_endl)*this<<'\n';return *this;}Writer&operator<<(const std::string&str){int st=0,ed=str.size();while(st<ed)putchar(str[st++]);return*this;}Writer(){}}cout;}
#define cin Fastio::cin
#define cout Fastio::cout
#define endl Fastio::endl
template<class Fun>class y_combinator_result{Fun fun_;public:template<class T>explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}template<class ...Args>decltype(auto) operator()(Args &&...args){return fun_(std::ref(*this), std::forward<Args>(args)...);}};template<class Fun>decltype(auto) y_combinator(Fun &&fun){return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));}

void init();void solve(int tc);
main()
{
    init();int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)solve(tc);
}
void init()
{
}
constexpr int N=1000000,B=200;
int a[N+1],pre[N+1],ans[N+1];
vector<tuple<int,int,int>>querys;
vector<tuple<int,int,int>>v[N+1];
bool cmp(const tuple<int,int,int>&a1,const tuple<int,int,int>&a2)
{
	auto [l1,r1,t1]=a1;
	auto [l2,r2,t2]=a2;
	return (l1/B==l2/B)?r1<r2:l1<l2;
}
int up[1<<9],val[1<<18],k;
int query(int v)
{
    return up[v>>9]+val[v];
}
void add(int v)
{
    for(int x=17;x>=9;x--)
    if(k>>x&1)
    {
        int l=(v^k^(1<<x))&~((1<<x)-1),r=l+(1<<x)-1;
        for(int y=l;y<r+1;y+=1<<9)up[y>>9]++;
    }
    for(int x=8;x>=0;x--)
    if(k>>x&1)
    {
        int l=(v^k^(1<<x))&~((1<<x)-1),r=l+(1<<x)-1;
        for(int y=l;y<r+1;y++)val[y]++;
    }
}
void solve([[maybe_unused]]int tc)
{
	int n;
	cin>>n>>k;
    k++;
	for(int x=1;x<=n;x++)
	cin>>a[x],pre[x]=query(a[x]),add(a[x]);
    int m;
    cin>>m;
	for(int x=1;x<=m;x++)
	{
		int l,r;
		cin>>l>>r;
		querys.emplace_back(l,r,x);
	}
	sort(querys.begin(),querys.end(),cmp);
	int l=1,r=0;
	for(auto [L,R,t]:querys)
	{
		if(r<R)v[l-1].emplace_back(r+1,R,-t);
		while(r<R)ans[t]+=pre[++r];
		if(l<L)v[r].emplace_back(l,L-1,-t);
		while(l<L)ans[t]+=pre[l++]+1;
		if(r>R)v[l-1].emplace_back(R+1,r,t);
		while(r>R)ans[t]-=pre[r--];
		if(l>L)v[r].emplace_back(L,l-1,t);
		while(l>L)ans[t]-=pre[--l]+1;
	}
    memset(up,0,sizeof(up));
    memset(val,0,sizeof(val));
    for(int x=1;x<=n;x++)
    {
        add(a[x]);
        for(auto [L,R,t]:v[x])
        for(int y=L;y<=R;y++)
        ans[abs(t)]+=(t>0?1:-1)*query(a[y]);
    }
	int lst=0;
	for(auto [L,R,t]:querys)
	ans[t]+=lst,lst=ans[t];
	for(int x=1;x<=m;x++)
	cout<<ans[x]<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 0ms
memory: 10740kb

input:

11 4
11 4 5 1 4 1 9 1 9 8 10
5
1 4
1 9
1 9
8 10
8 10

output:

2
12
12
1
1

result:

ok 5 number(s): "2 12 12 1 1"

Subtask #2:

score: 19
Accepted

Dependency #1:

100%
Accepted

Test #2:

score: 19
Accepted
time: 2ms
memory: 8772kb

input:

100 9878
6695 25377 5727 9878 15055 10108 15771 7736 11554 24853 2650 18844 31573 30110 32407 18847 3680 1922 23329 9122 16047 5063 22001 28302 23835 10041 2747 20756 18458 28357 22979 13626 24882 10019 10482 21779 30388 12216 15145 1229 30118 17594 4565 24050 30721 9365 3268 12263 797 9357 15415 22...

output:

0
13
848
2
919
336
593
138
801
9
110
388
494
406
13
22
972
81
138
198
3
196
84
20
12
17
167
79
32
223
147
15
110
62
7
233
49
242
829
21
599
62
28
51
801
194
639
198
869
15
6
174
133
27
269
40
493
672
29
554
242
27
534
452
295
851
16
1024
6
10
13
254
34
1038
206
181
25
437
300
66
906
299
8
870
877
22...

result:

ok 100 numbers

Subtask #3:

score: 19
Accepted

Dependency #2:

100%
Accepted

Test #3:

score: 19
Accepted
time: 0ms
memory: 8912kb

input:

1000 9957
2513 28133 26190 28051 10992 19271 11053 10798 27840 21303 3707 25889 2701 5666 22537 7119 19901 13091 30865 20950 27142 4971 26512 18325 27102 29926 4947 31212 16179 2076 5973 20290 19549 9557 11464 5581 31057 23808 2418 14093 10519 26453 8378 17562 9086 14138 31491 16928 18190 13411 5944...

output:

5811
50434
18691
129275
68076
5681
6393
7664
752
66954
825
6005
13135
26931
42
26306
66115
74911
36700
1019
20906
518
4119
458
3183
97459
9935
318
1704
4573
4635
662
1751
64636
35584
11197
70049
19023
35287
3242
1689
148660
7244
6256
30381
4042
20754
6925
70254
67439
70311
30481
7405
10562
2809
36
1...

result:

ok 1000 numbers

Subtask #4:

score: 0
Wrong Answer

Dependency #2:

100%
Accepted

Test #4:

score: 0
Wrong Answer
time: 77ms
memory: 9300kb

input:

200000 26351
29455 31132 8794 31579 7515 31811 27905 7641 16326 17298 9898 28764 16137 423 22542 15235 22739 30407 5230 2403 25465 582 22239 23942 13801 15015 18918 11827 19425 20741 11588 752 31326 17330 19987 23622 18518 9245 17682 18628 16297 29689 28478 19271 19030 23963 21666 30328 28650 19364 ...

output:

771462156
1282814907
988919745
2104601125
171585368
20114278
907377643
190962749
1205544902
-1934178636
9725156
-1956793763
-1905330049
1728248740
164441959
-324570285
1949288839
1787769746
445235924
369750002
-1788991075
184357542
-1910021291
723950727
709280821
-1143148557
-998060942
1054674256
42...

result:

wrong answer 1st numbers differ - expected: '9361396748', found: '771462156'

Subtask #5:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 632ms
memory: 67528kb

input:

200000 50
4 83 4 57 16 32 21 19 19 30 10 84 62 10 21 59 14 72 60 38 90 26 23 4 10 59 43 1 82 9 94 27 3 58 12 8 54 97 30 74 63 44 15 22 17 20 45 100 55 3 65 23 18 53 53 4 28 90 1 31 88 15 64 42 3 83 12 84 19 8 56 85 49 6 57 97 97 22 59 14 64 3 22 17 61 22 92 79 5 88 53 20 83 13 28 85 28 77 44 19 1 85...

output:

342347193
-376479490
1098814786
-1586187730
72779355
32360398
235377383
266647718
-453026182
946930359
21266954
-1310400032
1482071423
292723
46867973
23603825
-1580920167
798221669
89070258
53455663
1362445792
2039836965
1734388933
1090134969
4419822
302048676
92087776
1221223257
131418477
82234901...

result:

wrong answer 2nd numbers differ - expected: '3918487806', found: '-376479490'

Subtask #6:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

0%