QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#748626#7615. Sequence Foldingxh_team#TL 0ms3568kbC++201.3kb2024-11-14 20:54:232024-11-14 20:54:24

Judging History

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

  • [2024-11-14 20:54:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3568kb
  • [2024-11-14 20:54:23]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define x first
#define y second
#define PII pair<int,int>
#define lowbit(x) x&-x
//#define endl "\n"
#define lson 2*p
#define rson 2*p+1
const int N=5e5+10;
const int mod=1e9+7;
map<int,int> mp;
int a[N];
void solve() {
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++) {
		cin>>a[i];
		mp[a[i]]=2;
	}
	for(int i=1;i<=m;i++) {
		int j=n-a[i]+1;
		if(mp[j]!=2) mp[j]=1;
	}
	//mp=1 为0
	//mp=2 为1
	//mp=3 自适应
	int ans=0;
	while(n>1) {
        vector<int> aa;
        for (auto [x, y] : mp) {
            if (!mp.count(n - x + 1)) {
                aa.push_back(n - x + 1);
            }
        }
        for (int x : aa) {
            mp[x] = 1;
        }
		for(auto [x,y]:mp) {
			if(x>n/2) break;
			int p=n-x+1;
			//cout<<x<<" "<<p<<" "<<mp[x]<<" "<<mp[p]<<endl;
			if(mp[p]==mp[x]) {
				continue;
			} else {
				if(mp[p]==3) {
					continue;
				}
				if(y==3) {
					mp[x]=mp[p];
					continue;
				}
				mp[x]=3;
				ans++;
			}
		}
        mp.erase(mp.find(n / 2 + 1), mp.end());
		n>>=1;
	}
	cout<<ans<<'\n';
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T=1;
	// cin>>T;
	while(T--) {
		solve();
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3568kb

input:

8 3
1 5 8

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

1 1
1

output:

0

result:

ok single line: '0'

Test #3:

score: -100
Time Limit Exceeded

input:

17179869184 100000
138476 774165 993977 1152277 1236393 1244970 1534017 1693701 1763926 1778781 1842066 1874644 1885666 2120429 2485344 2977941 3158255 3340476 3504862 4000117 4066652 4197639 4338723 4389163 4576965 4761601 5097091 5175412 5295902 5810551 5855982 6001770 6111262 6163309 6351547 6582...

output:


result: