Submission #615500

# Submission time Handle Problem Language Result Execution time Memory
615500 2022-07-31T09:56:51 Z 장태환(#8493) Sprinkler (JOI22_sprinkler) C++17
0 / 100
14 ms 20692 KB
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")

int N, L;
int qs, qe, n;
struct st
{
	vector<long long>r;
	int treeN;
	void init(int cnt)
	{
		for (treeN = 1; treeN < cnt; treeN *= 2);
		r.resize(2 * treeN +2, 1);
	}
	void upd(int s, int e, int i = 1)
	{
		if (s > qe || qs > e)
			return;
		if (qs <= s && e <= qe)
		{
			r[i] *= n;
			if (r[i] >= L)
				r[i] %= L;
			return;
		}
		upd(s, (s + e) / 2, i * 2);
		upd((s + e) / 2 + 1, e, i * 2 + 1);
	}
	int ge(int qs, int qe, int n, int i = 1)
	{
		if (qs == qe)
		{
			return r[i];
		}
		int m = (qs + qe) / 2;
		if (n > m)
		{
			return r[i] * ge(m + 1, qe, n, i * 2 + 1) % L;
		}
		else
		{
			return r[i] * ge(qs, m, n, i * 2) % L;
		}
	}
}arr[200100];
int d[201000];
int pos[200100];
int par[200100];
int st[201000];
int en[200100];
int c;
vector<int>li[201000];
vector<pair<int, int>>dl[200100];
vector<int>dl2[200100];
void dfs(int n, int p = 0)
{
	st[n] = ++c;
	dl[d[n]].push_back({ st[n],n });
	dl2[d[n]].push_back(st[n]);
	int i;
	for (i = 0; i < li[n].size(); i++)
	{
		if (li[n][i] == p)
			continue;
		par[li[n][i]] = n;
		d[li[n][i]] = d[n] + 1;
		dfs(li[n][i], n);
	}
	en[n] = c;
}
signed main()
{
	scanf("%d %d", &N, &L);
	int i;
	for (i = 1; i < N; i++)
	{
		int a, b;
		scanf("%d %d", &a, &b);
		li[a].push_back(b);
		li[b].push_back(a);
	}
	dfs(1);
	for (i = 0; i <= N; i++)
	{
		arr[i].init(dl[i].size());
		int j;
		for (j = 0; j < dl[i].size(); j++)
		{
			pos[dl[i][j].second] = j;
		}
	}
	for (i = 1; i <= N; i++)
	{
		int a;
		scanf("%d", &a);
		arr[d[i]].r[pos[i] + arr[d[i]].treeN] = a;
	}
	int Q;
	scanf("%d", &Q);
	while (Q--)
	{
		int a;
		scanf("%d", &a);
		if (a == 1)
		{
			int b, c, w;
			scanf("%d %d %d", &b, &c, &w);
			int j;
			int dp = d[b];
			int cp = b;
			for (j = dp + c; j >= dp - c; j--)
			{
				if (j + dp - d[cp] * 2 + 2 <= c && cp != 1)
				{
					cp = par[cp];
				}
				if (j < 0)
					break;
				int lp = lower_bound(dl2[j].begin(), dl2[j].end(), st[cp]) - dl2[j].begin();
				if (lp != dl2[j].size() && dl2[j][lp] <= en[cp])
				{
					int rp = lower_bound(dl2[j].begin()+lp, dl2[j].end(), en[cp] + 1) - dl2[j].begin() - 1;
					qs = lp;
					qe = rp;
					n = w;
					arr[j].upd(0, arr[j].treeN - 1);
				}

			}
		}
		else
		{
			int b;
			scanf("%b", &b);
			cout << arr[d[b]].ge(0, arr[d[b]].treeN - 1, pos[b]) << '\n';
		}
	}

}

Compilation message

sprinkler.cpp: In function 'void dfs(int, int)':
sprinkler.cpp:62:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |  for (i = 0; i < li[n].size(); i++)
      |              ~~^~~~~~~~~~~~~~
sprinkler.cpp: In function 'int main()':
sprinkler.cpp:88:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   for (j = 0; j < dl[i].size(); j++)
      |               ~~^~~~~~~~~~~~~~
sprinkler.cpp:121:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     if (lp != dl2[j].size() && dl2[j][lp] <= en[cp])
      |         ~~~^~~~~~~~~~~~~~~~
sprinkler.cpp:135:12: warning: unknown conversion type character 'b' in format [-Wformat=]
  135 |    scanf("%b", &b);
      |            ^
sprinkler.cpp:135:10: warning: too many arguments for format [-Wformat-extra-args]
  135 |    scanf("%b", &b);
      |          ^~~~
sprinkler.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |  scanf("%d %d", &N, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:79:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |   scanf("%d %d", &a, &b);
      |   ~~~~~^~~~~~~~~~~~~~~~~
sprinkler.cpp:96:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   96 |   scanf("%d", &a);
      |   ~~~~~^~~~~~~~~~
sprinkler.cpp:100:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  100 |  scanf("%d", &Q);
      |  ~~~~~^~~~~~~~~~
sprinkler.cpp:104:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |   scanf("%d", &a);
      |   ~~~~~^~~~~~~~~~
sprinkler.cpp:108:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  108 |    scanf("%d %d %d", &b, &c, &w);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sprinkler.cpp:135:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |    scanf("%b", &b);
      |    ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 20692 KB Output isn't correct
2 Halted 0 ms 0 KB -