QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#405#201496#21703. 【NOIP Round #4】治病ytb2024fuqingranFailed.2023-10-05 23:14:582023-10-05 23:14:58

詳細信息

Extra Test:

Accepted
time: 28ms
memory: 257424kb

input:

17 17
199873 153921 537153 478401 477761 823329 593153 430513 685695 332929 458561 464577 64105 864593 588929 785341 661249
15 28 4 8 4 14 17
5 28 4 8 10 12 5
13 22 8 8 17 7 16 5 9 6 14
3 10 15 14 11 13 6 5 3 10 8 16 1 9 12 2 15 4
25 29 6 16 2 15 8 10 3
3 21 8 12 3 14 15 11 2 7 17
22 26 5 10 17 16 4...

output:

196441587 193586980 189315663 186444855 195404519 175116485 199522848 204386846 204386846 204386846 202473242 203922269 201644066 203928285 204386846 204386846 204386846 

result:

ok 17 numbers

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201496#21703. 【NOIP Round #4】治病fuqingran100 ✓2041ms433412kbC++147.7kb2023-10-05 14:43:582023-10-05 14:43:58

answer

#include<bits/stdc++.h>
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC target("avx")
#pragma GCC optimize(2)
#pragma GCC optimize(3,"Ofast","inline")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
using namespace std;
namespace fast_IO {
#define FASTIO
#define IOSIZE 100000
	char ibuf[IOSIZE], obuf[IOSIZE];
	char *p1 = ibuf, *p2 = ibuf, *p3 = obuf;
#ifdef ONLINE_JUDGE
#define getchar() ((p1==p2)and(p2=(p1=ibuf)+fread(ibuf,1,IOSIZE,stdin),p1==p2)?(EOF):(*p1++))
#define putchar(x) ((p3==obuf+IOSIZE)&&(fwrite(obuf,p3-obuf,1,stdout),p3=obuf),*p3++=x)
#endif//fread in OJ, stdio in local
	
#define isdigit(ch) (ch>47&&ch<58)
#define isspace(ch) (ch<33)
	template<typename T> inline T read() {
		T s = 0;
		int w = 1;
		char ch;
		while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1;
		if (ch == EOF) return false;
		while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar();
		return s * w;
	}
	template<typename T> inline bool read(T &s) {
		s = 0;
		int w = 1;
		char ch;
		while (ch = getchar(), !isdigit(ch) and (ch != EOF)) if (ch == '-') w = -1;
		if (ch == EOF) return false;
		while (isdigit(ch)) s = s * 10 + ch - 48, ch = getchar();
		return s *= w, true;
	}
	inline bool read(char &s) {
		while (s = getchar(), isspace(s));
		return true;
	}
	inline bool read(char *s) {
		char ch;
		while (ch = getchar(), isspace(ch));
		if (ch == EOF) return false;
		while (!isspace(ch)) *s++ = ch, ch = getchar();
		*s = '\000';
		return true;
	}
	template<typename T> inline void print(T x) {
		if (x < 0) putchar('-'), x = -x;
		if (x > 9) print(x / 10);
		putchar(x % 10 + 48);
	}
	inline void print(char x) {
		putchar(x);
	}
	inline void print(char *x) {
		while (*x) putchar(*x++);
	}
	inline void print(const char *x) {
		for (int i = 0; x[i]; i++) putchar(x[i]);
	}
#ifdef _GLIBCXX_STRING
	inline bool read(std::string& s) {
		s = "";
		char ch;
		while (ch = getchar(), isspace(ch));
		if (ch == EOF) return false;
		while (!isspace(ch)) s += ch, ch = getchar();
		return true;
	}
	inline void print(std::string x) {
		for (int i = 0, n = x.size(); i < n; i++)
			putchar(x[i]);
	}
#endif//string
	template<typename T, typename... T1> inline int read(T& a, T1&... other) {
		return read(a) + read(other...);
	}
	template<typename T, typename... T1> inline void print(T a, T1... other) {
		print(a);
		print(other...);
	}
	
	struct Fast_IO {
		~Fast_IO() {
			fwrite(obuf, p3 - obuf, 1, stdout);
		}
	} io;
	template<typename T> Fast_IO& operator >> (Fast_IO &io, T &b) {
		return read(b), io;
	}
	template<typename T> Fast_IO& operator << (Fast_IO &io, T b) {
		return print(b), io;
	}
#define cout io
#define cin io
#define endl '\n'
}
using namespace fast_IO;
#define int long long
const int N=5e5+5;
struct kcx
{
	int id,xi;
	bool operator<(const kcx &b)const
	{
		if(xi==b.xi)return id<b.id;
		return xi>b.xi;
	}
};
struct node
{
	int l,r,siz;
	__int128 val;
	priority_queue<kcx>q;
};
struct did
{
	int xi,ki,flag,id,ri;
	vector<int>a;
	bool operator<(const did &b)
	{
		if(xi==b.xi)
		{
			if(flag==b.flag)return id>b.id;
			return flag<b.flag;
		}
		return xi<b.xi;
	}
}s[2*N];
int n,m,cnt;
__int128 fqr[N],v[N];
__int128 ans;
vector<int>kong[N];
map<int,int>Map[N];
struct SMT
{
	node tree[4*N];
	void push_up(int x)
	{
		tree[x].val=tree[x*2].val+tree[x*2+1].val;
		tree[x].siz=tree[x*2].siz+tree[x*2+1].siz;
	}
	void build(int x,int l,int r)
	{
		tree[x].l=l;
		tree[x].r=r;
		if(l==r)return ;
		int mid=l+r>>1;
		build(x*2,l,mid);
		build(x*2+1,mid+1,r);
		push_up(x);
	}
	void modify(int x,int l,int r,int flag,int tim,int id,int ri)
	{
		if(tree[x].l>r||tree[x].r<l)return ;
		if(tree[x].l>=l&&tree[x].r<=r)
		{
			if(flag)
			{
				tree[x].q.pop();
				tree[x].siz--;
				if(!tree[x].siz)
				{
					tree[x].val=0,fqr[id]+=v[l]*(tim-kong[id][Map[id][l]]);
//					cout<<"cnm: "<<id<<' '<<(long long)v[l]<<' '<<tim<<' '<<kong[id][Map[id][l]]<<'\n';
				}
				else if(tree[x].siz==1)
				{
					int sb=tree[x].q.top().id;
//					cout<<"sbfqr: "<<sb<<' '<<tim<<' '<<'\n';
					kong[sb][Map[sb][l]]=tim;	
				}
			}
			else
			{
				if(!tree[x].siz)tree[x].val=v[l],kong[id][Map[id][l]]=tim;
				else if(tree[x].siz==1)
				{
					int sb=tree[x].q.top().id;
					fqr[sb]+=v[l]*(tim-kong[sb][Map[sb][l]]);
				}
				tree[x].siz++;
				tree[x].q.push((kcx){id,ri});
			}
			return ;
		}
		modify(x*2,l,r,flag,tim,id,ri);
		modify(x*2+1,l,r,flag,tim,id,ri);
		push_up(x);
	}
}cyx;
signed main()
{
//	ios::sync_with_stdio(false);
//	cin.tie(NULL);cout.tie(NULL);
//	freopen("data.in","r",stdin);
//	freopen("kcx.out","w",stdout);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int x;
		cin>>x;
		v[i]=x;
	}
	for(int i=1;i<=n;i++)
	{
		int li,ri,ki;
		cin>>li>>ri>>ki;
		did t;
		t.xi=li;
		t.flag=0;
		t.ki=ki;
		t.id=i;
		t.a.resize(ki+2);
		t.ri=ri;
		kong[i].resize(ki+2);
		for(int j=1;j<=ki;j++)
		{
			cin>>t.a[j];
			Map[i][t.a[j]]=j;
		}
		s[++cnt]=t;
		s[++cnt]=t;
		
		s[cnt].xi=ri+1;
		s[cnt].flag=1;
	}
	
	sort(s+1,s+1+cnt);
	cyx.build(1,1,m);
	int last=0;
	for(int i=1;i<=cnt;i++)
	{
//		cout<<"the last: "<<last<<'\n';
//		cout<<"aminos: "<<s[i].id<<' '<<s[i].xi<<' '<<s[i].ki<<' '<<s[i].flag<<' '<<(long long)cyx.tree[1].val<<'\n';
		ans+=cyx.tree[1].val*(s[i].xi-last);
		for(int j=1;j<=s[i].ki;j++)
		{
			int x=s[i].a[j];
			cyx.modify(1,x,x,s[i].flag,s[i].xi,s[i].id,s[i].ri);	
		}
		last=s[i].xi;
	}
	for(int i=1;i<=n;i++)
	{
		int x=ans-fqr[i];
		cout<<x<<' ';
	}
	return 0;
}
/*
5 4
10000 1000 100 10
3 4 2 2 3
4 8 3 1 2 4
6 7 2 3 4
8 9 2 1 4
2 6 3 1 2 3

2 4
10000 1000 100 10
1 2 3 1 2 3 
1 2 4 1 2 3 4

368581418 376890308 370938068 370887444 353467002 372491685 359302974 344917786 376890308 371536481
368581418 376890308 370938068 370887444 353467002 372491685 359302974 344917786 376890308 371536481
*/