Submission #488954

# Submission time Handle Problem Language Result Execution time Memory
488954 2021-11-20T20:35:11 Z MilosMilutinovic Meteors (POI11_met) C++14
100 / 100
2605 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=300001;
int n,m,q,o[N],p[N],l[N],r[N],a[N],up[N],lo[N],ans[N];
ll tot[N],c[N];
VI qv[N],qs[N];

void modify(int x,int y) {
	for (;x<=m;x+=x&-x) c[x]+=y;
}
ll query(int x) {
	ll s=0;
	for (;x;x-=x&-x) s+=c[x];
	return s;
}

int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,m+1) scanf("%d",o+i),qv[o[i]].pb(i);
	rep(i,1,n+1) scanf("%d",p+i);
	scanf("%d",&q);
	rep(i,1,q+1) scanf("%d%d%d",l+i,r+i,a+i);
	rep(i,1,n+1) lo[i]=1,up[i]=q,ans[i]=q+1;
	rep(it,0,50) {
		rep(i,1,n+1) tot[i]=0;
		rep(i,1,q+1) qs[i].clear();
		rep(i,1,n+1) if (lo[i]<=up[i])
			qs[(lo[i]+up[i])/2].pb(i);
		rep(i,1,m+5) c[i]=0;
		rep(i,1,q+1) {
			if (l[i]<=r[i]) {
				modify(l[i],a[i]);
				modify(r[i]+1,-a[i]);
			} else {
				modify(l[i],a[i]);
				modify(1,a[i]);
				modify(r[i]+1,-a[i]);
			}
			for (auto x:qs[i]) for (auto y:qv[x]) if (tot[x]<p[x]) 
				tot[x]+=query(y);
		}
		rep(i,1,n+1) {
			if (lo[i]>up[i]) continue;
			int md=(lo[i]+up[i])/2;
			if (tot[i]>=p[i]) ans[i]=md,up[i]=md-1;
			else lo[i]=md+1;
		}
	}
	rep(i,1,n+1) {
		if (ans[i]>q) puts("NIE");
		else printf("%d\n",ans[i]);
	}
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
met.cpp:39:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  rep(i,1,m+1) scanf("%d",o+i),qv[o[i]].pb(i);
      |               ~~~~~^~~~~~~~~~
met.cpp:40:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  rep(i,1,n+1) scanf("%d",p+i);
      |               ~~~~~^~~~~~~~~~
met.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d",&q);
      |  ~~~~~^~~~~~~~~
met.cpp:42:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |  rep(i,1,q+1) scanf("%d%d%d",l+i,r+i,a+i);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 14540 KB Output is correct
2 Correct 11 ms 14412 KB Output is correct
3 Correct 11 ms 14412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 14412 KB Output is correct
2 Correct 10 ms 14460 KB Output is correct
3 Correct 10 ms 14584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 127 ms 16360 KB Output is correct
2 Correct 213 ms 18608 KB Output is correct
3 Correct 185 ms 18136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 178 ms 17516 KB Output is correct
2 Correct 188 ms 17576 KB Output is correct
3 Correct 213 ms 18708 KB Output is correct
4 Correct 49 ms 16964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 155 ms 16924 KB Output is correct
2 Correct 156 ms 19348 KB Output is correct
3 Correct 106 ms 15076 KB Output is correct
4 Correct 185 ms 18668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 220 ms 15948 KB Output is correct
2 Correct 197 ms 17592 KB Output is correct
3 Correct 151 ms 16380 KB Output is correct
4 Correct 201 ms 19940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1771 ms 36104 KB Output is correct
2 Correct 1324 ms 22772 KB Output is correct
3 Correct 563 ms 17552 KB Output is correct
4 Correct 2377 ms 64840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1718 ms 34672 KB Output is correct
2 Correct 1287 ms 22768 KB Output is correct
3 Correct 400 ms 16832 KB Output is correct
4 Correct 2605 ms 65536 KB Output is correct