首页 > 其他分享 >E. Data Structures Fan

E. Data Structures Fan

时间:2024-05-28 19:33:28浏览次数:18  
标签:ansz int Structures ll cin Fan ans include Data

非常有意思的一道思维题!!!!
先上两个题解:

题解1:

题解2:


总的思路就是伪“前缀和”,然后维护选0还是选1的异或和就够了。
如果改变,就直接像前缀和那样改,证明理由就是0^a = a ;a^a =0;

代码:

#define _CRT_SECURE_NO_WARNINGS 
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<sstream>
#include<string>
#include<string.h>
#include<iomanip>
#include<stdlib.h>
#include<map>
#include<queue>
#include<limits.h>
#include<climits>
#include<fstream>
#include<stack>
typedef long long ll;
using namespace std;
const int N = 1e5 + 10;
ll a[N];
int main()
{
	ios::sync_with_stdio(false); cin.tie(0), cout.tie(0);
	ll t; cin >> t;
	while (t--)
	{
		ll n; cin >> n;
		for (int i = 1; i <= n; i++)cin >> a[i];
		string s; cin >> s;
		ll ans = 0; ll ansz = 0;
		for (int i = 0; i < s.length(); i++)
			if (s[i] - '0')
				if (!ans)ans = a[i + 1];
				else ans ^= a[i + 1];
			else
				if (!ansz)ansz = a[i + 1];
				else ansz ^= a[i + 1];
		for (int i = 1; i <= n; i++)
			a[i] ^= a[i - 1];
		ll q; cin >> q;
		while (q--)
		{
			ll op; cin >> op;
			if (op == 1)
			{
				ll x, y; cin >> x >> y;
				ans ^= a[x - 1] ^ a[y];
				ansz ^= a[x - 1] ^ a[y];
			}
			else
			{
				int t; cin >> t;
				if(t)cout << ans << ' ';
				else cout << ansz << ' ';
			}
		}
		cout << '\n';
	}
	return 0;
}

标签:ansz,int,Structures,ll,cin,Fan,ans,include,Data
From: https://www.cnblogs.com/zzzsacmblog/p/18218685

相关文章

  • Error creating bean with name ‘dataSource‘ defined in class path resource解决
    报错信息ERROR3592—[restartedMain]o.s.boot.SpringApplication:Applicationrunfailedorg.springframework.beans.factory.BeanCreationException:Errorcreatingbeanwithname‘dataSource’definedinclasspathresource[org/springframework/boot/autoconfi......
  • 在自己页面中嵌入Grafana
    在自己页面中嵌入grafana:<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>EmbedGrafana</title></head><body><iframesrc="http://192.168.30.242:3000/d/......
  • datax 抽取hive表到doris
    datax读取hive表有两种方式,一种是读取hdfs文件路径HDFSReader,因为hive是存储在hdfs上。第二种是读取hive表RDBMSReader。HDFSReader{"job":{"setting":{"speed":{"channel":3},"......
  • 【问题记录】Cause: java.sql.SQLRecoverableException: No more data to read from s
    异常说明:   当Oracle客户端(应用)接收数据库服务器发送的数据时,它会从套接字中读取数据。如果在读取数据的过程中,套接字中没有更多的数据可供读取,那么Oracle客户端就会报告“没有更多数据从套接字读取”错误。常见原因:应用使用了连接池,当从连接池取得的connection失效或者超......
  • LeetCode-2877. 从表中创建 DataFrame
    2877.从表中创建DataFrame编写一个解决方案,基于名为student_data的二维列表创建一个DataFrame。这个二维列表包含一些学生的ID和年龄信息。DataFrame应该有两列,student_id和age,并且与原始二维列表的顺序相同。返回结果格式如下示例所示。示例1:输入:student_data:[......
  • HITSC_6_Abstract Data Type (ADT)
    AbstractionandUser-DefinedTypes......
  • Oracle数据库数据泵(Data Pump)导出与导入
    expdp(导出数据)基本语法:expdp"'/assysdba'"DIRECTORY=EXPDPSCHEMAS=用户名DUMPFILE=my20240528%U.DMPCLUSTER=NOLOGFILE=my_20240528EXPDP.LOG示例:导出用户下指定的表数据。expdp"'/assysdba'"DIRECTORY=EXPDPTABLES=usre1.table1,usre2.ta......
  • Wpf经验技巧-使用 d:DataContext 指定 DataContext 的类型.
    VM代码:V代码(版本1):没有指定DataContext的类型,所以下面的绑定并不知道P1和P3到底是什么,也就无法在代码编辑时检测出绑定是否正确.如果写错了,只能等到程序运行并打开这个窗口时报错才能知道.V代码(版本2):通过d:DataContext指定了DataContext的类型,所以下面的绑定可以知道......
  • WPF DataGrid使用 自动显示行号、全选、三级联动、拖拽
    1.DataGrid的使用自动显示行号(修复删除行时行号显示不正确)  ViewCodedgTool.LoadingRow+=newEventHandler<DataGridRowEventArgs>(dgTool_LoadingRow);dgTool.UnloadingRow+=newEventHandler<DataGridRowEventArgs>(dgTool_UnloadingRow);voi......
  • HITSC_4_Data Type and Type Checking
    目标静态/动态,可变/不变,Snapshot图,集合类,NULL数据类型基本数据类型没啥好说的对象数据类型String,Integer等区别Boxedprimitives将基本类型包装为对象类型,但不常用,通常是为了集合类而用层次结构对象结构有extends(继承)等关系操作既可以是普通的运算符,也可以是Ob......