首页 > 其他分享 >POI2007TET-Tetris Attack

POI2007TET-Tetris Attack

时间:2024-04-15 19:49:10浏览次数:27  
标签:tmp cur la int POI2007TET tr add Attack Tetris

POI #Year2007 #贪心 #树状数组

考虑每一对数的最小代价为,将当前的换到最近的下面

用树状数组记录中间有几个没有被消掉的

// Author: xiaruize
const int N = 2e5 + 10;

int n, m;
int la[N];

struct BIT
{
	int tr[N];

	void add(int x, int v)
	{
		while (x <= m)
		{
			tr[x] += v;
			x += x & -x;
		}
	}

	int sum(int x)
	{
		int res = 0;
		while (x)
		{
			res += tr[x];
			x -= x & -x;
		}
		return res;
	}

	int get(int l, int r)
	{
		return sum(r) - sum(l - 1);
	}
} tr;
vector<int> vec;
void solve()
{
	cin >> n;
	int res = 0;
	m = n * 2;
	int cur = 0;
	rep(i, 1, m)
	{
		int x;
		cin >> x;
		if (!la[x])
		{
			tr.add(i, 1);
			la[x] = i;
			cur++;
			continue;
		}
		tr.add(la[x], -1);
		int tmp = tr.get(la[x], i);
		res += tmp;
		per(i, cur - 1, cur - tmp) vec.push_back(i);
		cur--;
	}
	cout << res << endl;
	for (auto v : vec)
		cout << v + 1 << endl;
}

#ifndef ONLINE_JUDGE
bool end_of_memory_use;
#endif

signed main()
{
	// freopen(".in","r",stdin);
	// freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int testcase = 1;
	// cin >> testcase;
	while (testcase--)
		solve();
#ifndef ONLINE_JUDGE
	cerr << "Memory use:" << (&end_of_memory_use - &start_of_memory_use) / 1024.0 / 1024.0 << "MiB" << endl;
	cerr << "Time use:" << (double)clock() / CLOCKS_PER_SEC * 1000.0 << "ms" << endl;
#endif
	return 0;
}

标签:tmp,cur,la,int,POI2007TET,tr,add,Attack,Tetris
From: https://www.cnblogs.com/xiaruize/p/18136787

相关文章

  • CF1923B Monsters Attack! 题解
    题目简述数轴上有$n$个怪兽。最初第$i$个怪兽在$x_i$位置上,且血量为$a_i$。你在位置$0$上。在每秒钟会发生:你给任意怪兽发射总共$k$颗子弹,受到攻击的怪兽血量减一。血量小于等于$0$的怪兽死亡。没有死亡的怪兽向你移动一个单位。当一个怪兽来到你的位置,你就输......
  • 52 Things: Number 43: Describe some basic (maybe ineffective) defences against s
    52Things:Number43:Describesomebasic(maybeineffective)defencesagainstsidechannelattacksproposedintheliteratureforAES52件事:第43件:描述AES文献中提出的针对侧信道攻击的一些基本(可能无效)防御措施 Thisisthelatestinaseriesofblogpoststoa......
  • 52 Things: Number 44: Describe some basic (maybe ineffective) defences against s
    52Things:Number44:Describesomebasic(maybeineffective)defencesagainstsidechannelattacksproposedintheliteratureforECC.52件事:第44件:描述文献中为ECC提出的一些针对侧信道攻击的基本(可能无效)防御措施。 Thisisthelatestinaseriesofblogposts......
  • 52 Things: Number 45: Describe some basic (maybe ineffective) defences against s
    52Things:Number45:Describesomebasic(maybeineffective)defencesagainstsidechannelattacksproposedintheliteratureforRSA.52件事:第45件:描述RSA文献中提出的针对侧信道攻击的一些基本(可能无效)防御措施。 Thisisthelatestinaseriesofblogpostst......
  • 52 Things: Number 39: What is the difference between a side-channel attack and a
    52Things:Number39:Whatisthedifferencebetweenaside-channelattackandafaultattack?52件事:第39件:侧通道攻击和故障攻击之间的区别是什么? Thisisthelatestinaseriesofblogpoststoaddressthelistof '52ThingsEveryPhDStudentShouldKnowT......
  • 52 Things: Number 33: How does the Bellcore attack work against RSA with CRT?
    52Things:Number33:HowdoestheBellcoreattackworkagainstRSAwithCRT?52件事:第33件:Bellcore攻击如何使用CRT对抗RSA? Thisisthelatestinaseriesofblogpoststoaddressthelistof'52ThingsEveryPhDStudentShouldKnowToDoCryptography':......
  • As a reader --> Apollon: A robust defense system against Adversarial Machine Lea
    ......
  • 6种常见的JWT Attack,绕过网站身份验证 - 3.爆力破解对称式加密签名
    简介JWT攻击是使用者向网站发送修改后的JWT,目标是冒充另一个身份的使用者,并绕过身份验证和存取控制。如果攻击者能够使用任意值创建自己的JWT有效令牌,他们能够升级自己的权限或冒充其他用户,完全控制他们的帐户。JWT常见攻击手法有以下几种:签名未验证JWT无签名爆力破解对称......
  • nand2tetris_hack汇编语言
    计算机我接触的第一台电脑是winXP系统,我拥有的第一台电脑是win7,也就说一开始我理解的计算机就有着好看的界面,灵活的操作性方式,拥有许多软件,可以做很多事情。我们可曾想过,大部分机器都有其专属用途,比如榨汁机只能用来榨汁、削皮刀只能用来削皮,而计算机,他可以播放视频、浏览网页等......
  • DNS Amplification Attack
    摘要DNSAmplificationAttack是一种基于反射的DDoS攻击,攻击者借助DNS服务器,产生更大的流量让目标服务器或网络瘫痪,从而达到拒绝服务的效果。DDoS的分类根据攻击目标和所属的层次,可以将DDoS攻击大体分为三类:针对网络带宽资源的DDoS攻击,如ICMPFlood、UPDFlood、DNSAmpli......