QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599779#8781. Element-Wise ComparisonericmegalovaniaCompile Error//C++171.6kb2024-09-29 10:37:142024-09-29 10:37:14

Judging History

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

  • [2024-09-29 10:37:14]
  • 评测
  • [2024-09-29 10:37:14]
  • 提交

answer

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,bmi,fma,popcnt")
#include<bits/stdc++.h>

#define ONLINE
#ifndef ONLINE
char DEBUG_BUFFER[1000];
#define debug(...) {sprintf(DEBUG_BUFFER,##__VA_ARGS__);\
cerr<<"\033[1;36m"<<DEBUG_BUFFER<<"\033[0;2m"<<"\033[0m";}
#else
#define debug(...) ;
#endif

using LL=long long;
using PII=std::pair<int,int>;

#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()

#define FAST_IO {std::ios::sync_with_stdio(false);std::cin.tie(nullptr);}
inline int read(){static int x; std::cin>>x; return x;}

#define N 50001
//#define N 6

int main(){
	FAST_IO;
	int n=read(),m=read();
	std::vector<int>pos(n);
	for(int i=0;i<n;i++){
		pos[read()-1]=i;
	}
	std::vector<std::bitset<N>>f(n),suf(m);
	std::bitset<N>tmp; tmp.reset();
	for(int x=n-1;x>=0;x--){
		f[pos[x]]=tmp>>pos[x];
		tmp[pos[x]]=1;
	}
#ifndef ONLINE
	for(int i=0;i<n;i++){
		debug("f[%d]=",i+1);
		cerr<<f[i]<<"\n";
	}
#endif
	LL ans=0;
	for(int i=0,last=-1;i<n-m+1;i++){
		if(i>last){
			last+=m;
			suf[0]=f[last];
			for(int j=1;j<m;j++){
				suf[j]=suf[j-1]&f[last-j];
			}
#ifndef ONLINE
			debug("update suf\n");
			debug("\tlast=%d\n",last);
			for(int j=0;j<m;j++){
				debug("suf[%d]=",j+1);
				cerr<<suf[j]<<"\n";
			}
#endif
			tmp.set();
		}
		ans+=(suf[last-i]&tmp).count();
		tmp&=f[i+m];
	}
	std::cout<<ans;
	return 0;
}

/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
*/

詳細信息

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from answer.code:3:
/usr/include/c++/13/bits/allocator.h: In destructor ‘std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()’:
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to ‘always_inline’ ‘std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]’: target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~