답안 #1026195

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1026195 2024-07-17T17:02:31 Z _rain_ Binaria (CCO23_day1problem1) C++14
25 / 25
187 ms 104024 KB
#include<bits/stdc++.h>
using namespace std;
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
namespace Random
{
	#define int long long
	int Rand(int l , int r)
		{
			return uniform_int_distribution<int>(l , r)(rng);
		} 
	#undef int 
}
 
using i64 = long long;
using ui64 = unsigned long long;
 
#define MASK(x) ((i64)(1) << (x))
#define BIT(mask , x) (((mask) >> (x)) & (1))
#define sz(x) (x).size()
#define all(x) (x).begin() , (x).end()
 
#define FOR(i ,a , b) for (int i = (a); i <= (b); ++i)
#define FORD(i , a , b) for (int i = (b); i >= (a); --i)
#define REP(i , a , b) for (int i = (a); i < (b); ++i)
#define REPD(i , a , b) for (int i = (b) - 1 ; i >= (a); --i)
 
template <class T> 
    void compress(vector<T> &a)
    {
        sort(a.begin() , a.end());
        a.resize(unique(a.begin() , a.end()) - a.begin());
        return;
    }
template<class T>
    void printArr(T& container , string separator = "" , string finish = "\n")
    {
        for (auto& item : container) cout << item << separator;
        cout << finish;
    }
template<class T>
    bool maximize(T &a , T b) {if (a < b) return a = b , true; else return false;}
template<class T>
    bool minimize(T &a , T b) {if (a > b) return a = b , true; else return false;}
template<class T>
    T gcd(T x , T y) {while (y) swap(y , x %= y); return x;}
template<class T>
    T lcm(T x , T y) {return (x * y) / gcd(x , y);}
 
//... INPUT
    void INPUT(string name)
    {
    	iostream::sync_with_stdio(false); cin.tie(0);
    	if (!fopen((name + ".inp").c_str() , "r")) return;
    	freopen((name + ".inp").c_str() , "r" , stdin);
    	freopen((name + ".out").c_str() , "w+" , stdout);
    	return;
    }
 
const int maxn = 1e6;
int a[maxn + 2] , ID[maxn + 2] , n , k , length;
 
//... MOD OPERATOR
	const int MOD = 1e6 + 3;
	int add(int a , int b)
	{
		return (a + b >= MOD ? a + b - MOD : a + b);
	}
	int mul(int a , int b)
	{
		return (i64)a * b % MOD;
	}
	int _pow(int a , int b)
	{
		int res = 1;
		for (; b ; b >>= 1 , a = mul(a,a))
			if (b&1) res = mul(res,a);
		return res;
	}
	int fac[maxn + 2] , inv[maxn + 2];
	void pre()
	{
		fac[0] = 1;
		FOR(i,1,maxn) fac[i] = mul(fac[i - 1] , i);
		inv[maxn] = _pow(fac[maxn] , MOD - 2);
		FORD(i,1,maxn) inv[i - 1] = mul(inv[i] , i);
		return;
	}
	int C(int x , int y)
	{
		return (i64)fac[y] * inv[x] % MOD * inv[y - x] % MOD;
	}
 
class segment_tree
{
public:
	vector<int> st;
	vector<int> lazy;
	void init(int n)
	{
		st.assign(n*4+2,{0});
		lazy.assign(n*4+2,{0});
		return;
	}
	void build(int node , int l , int r)
	{
		if (l == r) st[node] = a[l];
		else 
		{
			int m = l + r >> 1;
			build(node*2,l,m);
			build(node*2+1,m+1,r);
			st[node] = min(st[node*2],st[node*2+1]);
		}
		return;
	}
	void pushdown(int node)
	{
		int& t = lazy[node];
		st[node*2] += t , lazy[node*2] += t;
		st[node*2+1] += t , lazy[node*2+1] += t;
		t = 0;
		return;
	}
	void update(int node , int l , int r , int u , int v , int val)
	{
		if (l > v || r < u) return;
		if (u <= l && r <= v)
				{
					st[node] += val;
					lazy[node] += val;
					return;
				}
		int m = l + r >> 1;
		pushdown(node);
		update(node*2,l,m,u,v,val);
		update(node*2+1,m+1,r,u,v,val);
		st[node] = min(st[node*2],st[node*2+1]);
		return;
	}
	int get(int node , int l , int r , int u , int v)
	{
		if (l > v || r < u) return (int)1e9 + 7;
		if (u <= l && r <= v) return st[node];
		int m = l + r >> 1;
		pushdown(node);
		return min(get(node*2,l,m,u,v),get(node*2+1,m+1,r,u,v));
	}
};
segment_tree st1;
vector<int> bag[maxn + 2];
int s[maxn + 2] , orz[maxn + 2];
 
void del(int x , int sub)
{
	int lim = min(x + k - 1 , n);
	st1.update(1,1,n,x,lim,-sub);
}
 
int32_t main()
{
	INPUT("main");
		cin >> n >> k;
		pre();
		length = n - k + 1;
		FOR(i,k,n) cin >> a[i];
		st1.init(n);
		FOR(i,1,k) 
			{
				ID[i] = i;
				bag[ID[i]].push_back(i);
			}
		FOR(i,1,n) s[i] = -1;
		st1.build(1,1,n);
		FOR(i,k+1,n)
		{
			if (a[i] - a[i - 1]==0)
			{
				if (ID[i - k] == 0) s[i] = s[i - k];
				else 
				{
					ID[i] = ID[i - k];
					bag[ID[i]].push_back(i);
				}
			}
			else if (abs(a[i] - a[i - 1]) == 1)
			{
				if (a[i] - a[i - 1] == 1)
				{
					if(ID[i - k] != 0)
					{
						for (auto& x : bag[ID[i - k]]) 
							s[x] = 0;
						bag[ID[i - k]].clear();
						ID[i - k] = 0;
					}
					else s[i - k] = 0;
					s[i] = 1;
					del(i,s[i]);
				}
				else
				if (a[i] - a[i - 1] == -1) 
				{
					if(ID[i - k] != 0)
					{
						for (auto& x : bag[ID[i - k]]) 
							{
								s[x] = 1;
								del(x,s[x]);
							}
						
						bag[ID[i - k]].clear();
						ID[i - k] = 0;
					}
					else 
					{
						s[i - k] = 1;
						del(i-k,s[i-k]);
					}
					s[i] = 0;
				}
			}
			else if (abs(a[i] - a[i - 1]) >= 2)
					{
						cout << 0;
						return 0;
					}
		}
		int answer = 0;
		FOR(i,1,k)
		{
			if (s[i] != -1) a[k] -= s[i];
				else ++answer;
		}
		cout << C(a[k],answer) << '\n';
	cerr << "\nTIME RUN : " << 1000 * clock() / CLOCKS_PER_SEC << "MS\n";
	return 0;
}

Compilation message

Main.cpp: In member function 'void segment_tree::build(int, int, int)':
Main.cpp:110:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  110 |    int m = l + r >> 1;
      |            ~~^~~
Main.cpp: In member function 'void segment_tree::update(int, int, int, int, int, int)':
Main.cpp:134:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  134 |   int m = l + r >> 1;
      |           ~~^~~
Main.cpp: In member function 'int segment_tree::get(int, int, int, int, int)':
Main.cpp:145:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  145 |   int m = l + r >> 1;
      |           ~~^~~
Main.cpp: In function 'void INPUT(std::string)':
Main.cpp:55:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |      freopen((name + ".inp").c_str() , "r" , stdin);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:56:13: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |      freopen((name + ".out").c_str() , "w+" , stdout);
      |      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
13 Correct 15 ms 37208 KB Output is correct
14 Correct 16 ms 37388 KB Output is correct
15 Correct 16 ms 37212 KB Output is correct
16 Correct 16 ms 37212 KB Output is correct
17 Correct 16 ms 37212 KB Output is correct
18 Correct 16 ms 37392 KB Output is correct
19 Correct 18 ms 37212 KB Output is correct
20 Correct 18 ms 37208 KB Output is correct
21 Correct 16 ms 37208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
13 Correct 15 ms 37208 KB Output is correct
14 Correct 16 ms 37388 KB Output is correct
15 Correct 16 ms 37212 KB Output is correct
16 Correct 16 ms 37212 KB Output is correct
17 Correct 16 ms 37212 KB Output is correct
18 Correct 16 ms 37392 KB Output is correct
19 Correct 18 ms 37212 KB Output is correct
20 Correct 18 ms 37208 KB Output is correct
21 Correct 16 ms 37208 KB Output is correct
22 Correct 17 ms 37336 KB Output is correct
23 Correct 17 ms 37212 KB Output is correct
24 Correct 18 ms 37208 KB Output is correct
25 Correct 19 ms 37212 KB Output is correct
26 Correct 17 ms 37212 KB Output is correct
27 Correct 16 ms 37396 KB Output is correct
28 Correct 17 ms 37384 KB Output is correct
29 Correct 16 ms 37212 KB Output is correct
30 Correct 17 ms 37212 KB Output is correct
31 Correct 17 ms 37212 KB Output is correct
32 Correct 18 ms 37212 KB Output is correct
33 Correct 17 ms 37212 KB Output is correct
34 Correct 18 ms 37352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
13 Correct 15 ms 37208 KB Output is correct
14 Correct 16 ms 37388 KB Output is correct
15 Correct 16 ms 37212 KB Output is correct
16 Correct 16 ms 37212 KB Output is correct
17 Correct 16 ms 37212 KB Output is correct
18 Correct 16 ms 37392 KB Output is correct
19 Correct 18 ms 37212 KB Output is correct
20 Correct 18 ms 37208 KB Output is correct
21 Correct 16 ms 37208 KB Output is correct
22 Correct 17 ms 37336 KB Output is correct
23 Correct 17 ms 37212 KB Output is correct
24 Correct 18 ms 37208 KB Output is correct
25 Correct 19 ms 37212 KB Output is correct
26 Correct 17 ms 37212 KB Output is correct
27 Correct 16 ms 37396 KB Output is correct
28 Correct 17 ms 37384 KB Output is correct
29 Correct 16 ms 37212 KB Output is correct
30 Correct 17 ms 37212 KB Output is correct
31 Correct 17 ms 37212 KB Output is correct
32 Correct 18 ms 37212 KB Output is correct
33 Correct 17 ms 37212 KB Output is correct
34 Correct 18 ms 37352 KB Output is correct
35 Correct 75 ms 80832 KB Output is correct
36 Correct 183 ms 78656 KB Output is correct
37 Correct 109 ms 78324 KB Output is correct
38 Correct 81 ms 80608 KB Output is correct
39 Correct 72 ms 80828 KB Output is correct
40 Correct 100 ms 80752 KB Output is correct
41 Correct 187 ms 79688 KB Output is correct
42 Correct 85 ms 79256 KB Output is correct
43 Correct 76 ms 80292 KB Output is correct
44 Correct 65 ms 82552 KB Output is correct
45 Correct 68 ms 74320 KB Output is correct
46 Correct 66 ms 80728 KB Output is correct
47 Correct 57 ms 80568 KB Output is correct
48 Correct 56 ms 80828 KB Output is correct
49 Correct 75 ms 80812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
13 Correct 15 ms 37208 KB Output is correct
14 Correct 16 ms 37388 KB Output is correct
15 Correct 16 ms 37212 KB Output is correct
16 Correct 16 ms 37212 KB Output is correct
17 Correct 16 ms 37212 KB Output is correct
18 Correct 16 ms 37392 KB Output is correct
19 Correct 18 ms 37212 KB Output is correct
20 Correct 18 ms 37208 KB Output is correct
21 Correct 16 ms 37208 KB Output is correct
22 Correct 17 ms 37336 KB Output is correct
23 Correct 17 ms 37212 KB Output is correct
24 Correct 18 ms 37208 KB Output is correct
25 Correct 19 ms 37212 KB Output is correct
26 Correct 17 ms 37212 KB Output is correct
27 Correct 16 ms 37396 KB Output is correct
28 Correct 17 ms 37384 KB Output is correct
29 Correct 16 ms 37212 KB Output is correct
30 Correct 17 ms 37212 KB Output is correct
31 Correct 17 ms 37212 KB Output is correct
32 Correct 18 ms 37212 KB Output is correct
33 Correct 17 ms 37212 KB Output is correct
34 Correct 18 ms 37352 KB Output is correct
35 Correct 75 ms 80832 KB Output is correct
36 Correct 183 ms 78656 KB Output is correct
37 Correct 109 ms 78324 KB Output is correct
38 Correct 81 ms 80608 KB Output is correct
39 Correct 72 ms 80828 KB Output is correct
40 Correct 100 ms 80752 KB Output is correct
41 Correct 187 ms 79688 KB Output is correct
42 Correct 85 ms 79256 KB Output is correct
43 Correct 76 ms 80292 KB Output is correct
44 Correct 65 ms 82552 KB Output is correct
45 Correct 68 ms 74320 KB Output is correct
46 Correct 66 ms 80728 KB Output is correct
47 Correct 57 ms 80568 KB Output is correct
48 Correct 56 ms 80828 KB Output is correct
49 Correct 75 ms 80812 KB Output is correct
50 Correct 83 ms 82516 KB Output is correct
51 Correct 96 ms 82432 KB Output is correct
52 Correct 92 ms 82264 KB Output is correct
53 Correct 179 ms 78160 KB Output is correct
54 Correct 107 ms 82260 KB Output is correct
55 Correct 85 ms 82516 KB Output is correct
56 Correct 87 ms 82256 KB Output is correct
57 Correct 146 ms 79884 KB Output is correct
58 Correct 91 ms 82516 KB Output is correct
59 Correct 147 ms 81516 KB Output is correct
60 Correct 140 ms 79368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 37208 KB Output is correct
2 Correct 15 ms 37212 KB Output is correct
3 Correct 13 ms 37212 KB Output is correct
4 Correct 14 ms 37212 KB Output is correct
5 Correct 17 ms 37400 KB Output is correct
6 Correct 18 ms 37388 KB Output is correct
7 Correct 16 ms 37212 KB Output is correct
8 Correct 17 ms 37212 KB Output is correct
9 Correct 16 ms 37388 KB Output is correct
10 Correct 17 ms 37208 KB Output is correct
11 Correct 16 ms 37212 KB Output is correct
12 Correct 18 ms 37212 KB Output is correct
13 Correct 15 ms 37208 KB Output is correct
14 Correct 16 ms 37388 KB Output is correct
15 Correct 16 ms 37212 KB Output is correct
16 Correct 16 ms 37212 KB Output is correct
17 Correct 16 ms 37212 KB Output is correct
18 Correct 16 ms 37392 KB Output is correct
19 Correct 18 ms 37212 KB Output is correct
20 Correct 18 ms 37208 KB Output is correct
21 Correct 16 ms 37208 KB Output is correct
22 Correct 17 ms 37336 KB Output is correct
23 Correct 17 ms 37212 KB Output is correct
24 Correct 18 ms 37208 KB Output is correct
25 Correct 19 ms 37212 KB Output is correct
26 Correct 17 ms 37212 KB Output is correct
27 Correct 16 ms 37396 KB Output is correct
28 Correct 17 ms 37384 KB Output is correct
29 Correct 16 ms 37212 KB Output is correct
30 Correct 17 ms 37212 KB Output is correct
31 Correct 17 ms 37212 KB Output is correct
32 Correct 18 ms 37212 KB Output is correct
33 Correct 17 ms 37212 KB Output is correct
34 Correct 18 ms 37352 KB Output is correct
35 Correct 75 ms 80832 KB Output is correct
36 Correct 183 ms 78656 KB Output is correct
37 Correct 109 ms 78324 KB Output is correct
38 Correct 81 ms 80608 KB Output is correct
39 Correct 72 ms 80828 KB Output is correct
40 Correct 100 ms 80752 KB Output is correct
41 Correct 187 ms 79688 KB Output is correct
42 Correct 85 ms 79256 KB Output is correct
43 Correct 76 ms 80292 KB Output is correct
44 Correct 65 ms 82552 KB Output is correct
45 Correct 68 ms 74320 KB Output is correct
46 Correct 66 ms 80728 KB Output is correct
47 Correct 57 ms 80568 KB Output is correct
48 Correct 56 ms 80828 KB Output is correct
49 Correct 75 ms 80812 KB Output is correct
50 Correct 83 ms 82516 KB Output is correct
51 Correct 96 ms 82432 KB Output is correct
52 Correct 92 ms 82264 KB Output is correct
53 Correct 179 ms 78160 KB Output is correct
54 Correct 107 ms 82260 KB Output is correct
55 Correct 85 ms 82516 KB Output is correct
56 Correct 87 ms 82256 KB Output is correct
57 Correct 146 ms 79884 KB Output is correct
58 Correct 91 ms 82516 KB Output is correct
59 Correct 147 ms 81516 KB Output is correct
60 Correct 140 ms 79368 KB Output is correct
61 Correct 70 ms 103904 KB Output is correct
62 Correct 64 ms 103940 KB Output is correct
63 Correct 61 ms 104020 KB Output is correct
64 Correct 68 ms 104020 KB Output is correct
65 Correct 93 ms 91740 KB Output is correct
66 Correct 97 ms 94536 KB Output is correct
67 Correct 166 ms 85260 KB Output is correct
68 Correct 70 ms 101408 KB Output is correct
69 Correct 63 ms 104020 KB Output is correct
70 Correct 92 ms 104012 KB Output is correct
71 Correct 70 ms 104024 KB Output is correct