Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#define __USE_MINGW_ANSI_STDIO 0 #include <bits/stdc++.h> using namespace std; using ll = long long; #define int ll using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #defi...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <sstream> #include <iostream> #include <string> using namespace std; template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} typedef long long LL; string FB(LL n){ string ret=""; if(n%3==0)ret+="Fizz"; if(n%5==0)ret+="Buzz"; if(ret == "")ret = toString(...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> using namespace std; using ll = long long; using P = pair<int, int>; const ll MOD = 1000000007; ll count(ll n){ ll p = 1; ll d = 1; ll sd = 0; while(p * 10 <= n){ ll np = p * 10 - 1; ll div3 = np / 3 - (p-1) / 3; ll div5 = np / 5 - (p-1) / 5; ll ...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long s = sc.nextLong(); long left = 0; long right = (long) 1e17; while(left + 1 < right) { long c = (left + right) >>> 1; if (length(c) < s) { left = c; }else{ right ...
JAVA
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include<iostream> #include<map> #include<vector> #include<algorithm> #include<cmath> #include<climits> #include<ctime> #include<cstring> #include<stack> #include<queue> #include<sstream> #include<string> #define ALL(v) (v).begin(),(v).end() #define REP(i,p,n) for(int i=p;i<(int)(n);++i) #define rep(i,n) REP(i,0,n) #d...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <iostream> #include <cstdio> #include <vector> #include <map> #include <string> #include <set> #include <stack> #include <queue> #include <algorithm> #include <cmath> using namespace std; typedef unsigned long long ll; // v[i] := iが偶数のときは i/2 + 1桁とi/2 + 2桁 の15個の数字のFizzBuzzStringの文字数 // v[i] := iが奇数のときは i/2+2...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> #define FOR(i,k,n) for(int i=(k);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(x) begin(x),end(x) using namespace std; int64_t normal_15(int64_t digits) { return digits * 8 + 32; } int64_t digit(int64_t n) { if (n < 10) return 1; return digit(n/10) + 1; } string fizzbuzz(int64_t n...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <algorithm> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> using namespace std; #define fst first #define snd second using ll = long long; using I = pair<int, int>; ll g(ll X) { return X - X / 3 ...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <algorithm> #include <sstream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <functional> #include <iostream> #include <iomanip> #include <iterator> #include <map> #include <queue> #include <utility> #include <vector> using namespace std; typedef long long Long; #define ...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; lint dp[20][2][3][5][20]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); auto len = [&](lint x) -> lint { string s = to_string(x); i...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v)...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
import java.util.*; class Main{ static long calc(long a){ long ret=a/3*4+a/5*4; int l=0; for(long p=1;a>=p;p*=10){ l++; long R=Math.min(a,p*10); long L=p-1; ret+=((R-R/3-R/5+R/15)-(L-L/3-L/5+L/15))*l; } return ret; } public static void main(String args[]){ Scanner s=new Scanner(System.in); ...
JAVA
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include "bits/stdc++.h" using namespace std; typedef long long ll; using Int = ll; Int getLength(ll n) { Int len = 0; ll fb = 0, f = 0, b = 0; for (ll m = 1, d = 1; m <= n; m *= 10, ++d) { if (m * 10 - 1 <= n) { ll fbnext = (m * 10 - 1) / 15, fnext = (m * 10 - 1) / 3 - fbnext, bnext =...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> using namespace std; /* 1 12Fizz4BuzzFizz78Fiz 20 zzBuzz11Fizz1314Fizz 22 Buzz11Fizz1314FizzBu 100 34BuzzFizz3738FizzBu */ #define ll long long vector<ll>V; ll d[7][20]; void init(){ for(int i=0;i<20;i++)d[0][i]=i; d[1][0]=1; for(int i=1;i<20;i++)d[1][i]=d[1][i-1]*10; d[2][0]=5; for(int i=...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> using namespace std; using ll = long long; //[1..s] ll fbfbnum(ll s) { ll fizz = s / 3; ll buzz = s / 5; return (fizz + buzz) * 4; } //[n2..n) ll f(ll n, ll n2, int cnt) { n--; n2--; ll fbcnt = fbfbnum(n) - fbfbnum(n2); ll fbnum = n / 3 + n / 5 - n / 15 - (n2 / 3 + n2...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <bits/stdc++.h> using namespace std; #define rep(i,x,y) for(int i=(x);i<(y);++i) #define mp(a,b) make_pair((a),(b)) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define dump(x) #endif typedef long...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include<bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(),A.end() #define RALL(A) A.rbegin(),A.rend() typedef long long LL; typedef pair<int,int> P; const LL mod=1000000007; const LL LINF=1LL<<60; const int ...
CPP
p01555 FizzBuzz
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number An example of the progress of the game is shown below. 1, 2, Fizz, 4, Buzz,...
7
0
#include <iostream> using namespace std; long long int calc(long long int m){ --m; long long int t = 1LL, ret = 0LL, l = 1LL; ret += m/3*4 + m/5*4; while(t*10 < m){ ret += l*(t*10 - t*10/3 - t*10/5 + t*10/15 - t + t/3 + t/5 - t/15); t *= 10LL; ++l; } ret += l*(m - m/3 - m/5 + m/15 - t + t/3 + t...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<stdio.h> #include<algorithm> #include<vector> #include<queue> using namespace std; int p[110]; int q[110]; int r[110]; vector<int>g[110]; int g2[110][110]; int UF[110]; int FIND(int a){ if(UF[a]<0)return a; return UF[a]=FIND(UF[a]); } void UNION(int a,int b){ a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<iostream> #include<string> #include<vector> #include<queue> #include<stack> #include<map> #include<set> #include<algorithm> #include<functional> #include<cstdio> #include<cstdlib> #include<cmath> using namespace std; #define mind(a,b) (a>b?b:a) #define maxd(a,b) (a>b?a:b) #define absd(x) (x<0?-(x):x) #define ...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> using namespace std; struct SCC{ int V; vector<vector<int> > G,rG,T; vector<int> vs,used,cmp; SCC(){} SCC(int V):V(V){init();} void init(){ G.clear(); rG.clear(); vs.clear(); used.clear(); cmp.clear(); T.clear(); G.resize(V); rG.resize(V); use...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> #define MAX_V 110 #define N 110 using namespace std; /* ?????£?????????????§£ O(|V|+|E|) */ int V; //????????° vector<int> G[MAX_V]; //??°???????????£??\??????????????¨??? vector<int> rG[MAX_V];//?????????????????????????????°?????? vector<int> vs; //??°????????????????????? bool used[MA...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> #include <string> #include <iostream> #include <set> #include <map> #include <time.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 100000...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> using namespace std; #define int long long #define all(v) (v).begin(), (v).end() #define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__) #define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++) #define rep(i, n) reps(i, 0, n) template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> using namespace std; struct StronglyConnectedComponents { vector< vector< int > > gg, rg; vector< pair< int, int > > edges; vector< int > comp, order, used; StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {} void add_edge(int x, int y) { gg[x].pu...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep1(i,n) for(int i=1;i<=(int)(n);i++) #define all(c) c.begin(),c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x,y) x=min(x,y) #define chmax(x,y) x=max(x,y) using...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <algorithm> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <vector> using namespace std; template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; } typedef vector<vector<int>> graph; // SCC Strongly Connected Component 強連結成分分解 struct SCC { int V; int cV...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> using namespace std; struct StronglyConnectedComponents { vector< vector< int > > gg, rg; vector< pair< int, int > > edges; vector< int > comp, order, used; StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {} void add_edge(int x, int y) { gg[x].pu...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; #define fi first #define se second #define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++) #define rep(i,n) repl(i,0,n) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<<x<<endl #de...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> #define MAX_V 110 #define N 110 using namespace std; /* ?????£?????????????§£ O(|V|+|E|) */ int V; //????????° vector<int> G[MAX_V]; //??°???????????£??\??????????????¨??? vector<int> rG[MAX_V];//?????????????????????????????°?????? vector<int> vs; //??°????????????????????? bool used[MA...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> using namespace std; #define int long long typedef vector<int>vint; typedef pair<int,int>pint; typedef vector<pint>vpint; #define rep(i,n) for(int i=0;i<(n);i++) #define reps(i,f,n) for(int i=(f);i<(n);i++) #define all(v) (v).begin(),(v).end() #define each(it,v) for(__typeof((v).begin()) it=(v...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> #include <string> #include <iostream> #include <set> #include <map> #include <time.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 100000...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def scc(N, G, RG): order = [] used = [0]*N group = [None]*N def dfs(s): used[s] = 1 for t in G[s]: if not used[t]: dfs(t) order.append(s) def rdfs(s, c...
PYTHON3
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> using namespace std; struct StronglyConnectedComponents { vector< vector< int > > gg, rg; vector< pair< int, int > > edges; vector< int > comp, order, used; StronglyConnectedComponents(size_t v) : gg(v), rg(v), comp(v, -1), used(v, 0) {} void add_edge(int x, int y) { gg[x].pu...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; struct edge { int from, to; }; using edges = std::vector<edge>; using graph = std::vector<edges>; void add_edge(graph& g, int from, int to) { g[from].push_back((edge){from, to}); } int scc(graph& G, std::vector<int>& cmp) { int V...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> #define int long long #define MAX_T 10005 #define MAX_V 105 using namespace std; typedef pair<int,int> P; /* ?????£?????????????§£ O(|V|+|E|) */ int V; //????????° vector<int> G[MAX_V]; //??°???????????£??\??????????????¨??? vector<int> rG[MAX_V];//?????????????????????????????°?????? vector<...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <queue> #include <stack> #include <map> #include <set> #include <unordered_map> #include <unordered_set> #include <complex> #include <functional> #include <ca...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include<bits/stdc++.h> #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--) #define all(a) (a).begin(),(a).end() #define INIT(a) memset(a,0,sizeof(a)) #define fs first #define sc second #define pb push_back #define sz size() using namespace std; const int MAX_N = 110; const...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<int, int> PII; const int MAXN = 200, MAXT = 10000 + 10; vector<int> G[MAXN]; bool mark[MAXN]; int p[MAXN], t[MAXN], k[MAXN]; int N, M, T; namespace SCC { vector<int> SCC[MAXN], SCCG[MAXN]; int low[MAXN], dfn[MAXN], ord[MAXN]; int s...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> #define REP(i,n) for(int i=0; i<(int)(n); ++i) using namespace std; typedef vector<int> Node; typedef vector<Node> Graph; Graph G, RG; void dfs(int u, vector<bool>& used, vector<int>& order) { if(used[u]) return; used[u] = true; for(int v : G[u]) { dfs(v, used, order); ...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
//Name: Website Tour //Level: 4 //Category: グラフ,Graph,動的計画法,DP,強連結成分分解,個数制限付きナップサック問題 //Note: /** * 以下のどちらかの条件を満たすとき、ある頂点の広告は好きなだけ見ることができる。 * ・自己ループをもつ * ・この頂点を含む強連結成分内に他の頂点が存在する * したがって、強連結成分分解したグラフを1ノードずつたどりながら、個数制限付きナップサック問題を解いていけばよい。 * 個数制限付きナップサック問題は、荷物の重さを2冪で分解することにより、O(N log W)で計算できる。 * * オーダーは O(NT log ...
CPP
p01710 Website Tour
Problem Statement You want to compete in ICPC (Internet Contest of Point Collection). In this contest, we move around in $N$ websites, numbered $1$ through $N$, within a time limit and collect points as many as possible. We can start and end on any website. There are $M$ links between the websites, and we can move be...
7
0
#include <bits/stdc++.h> using namespace std; inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;} template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();} template<class T> inline T sqr(T x) {return x*x;} typedef vector<int> vi; typedef vector<vi> vvi; typed...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include<bits/stdc++.h> using namespace std; int main(){ int n; cin >> n; for(int i=0;i<n;i++){ long long x,y; cin >> x >> y; if(x==y)cout << 1 << " " << 0 << endl; else if(x%2==0||y%2==0)cout << 1 << " " << 1 << endl; else { if(x>y)swap(x,y); if(y%x==0){ y/=x; x/=x; } ...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<c...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include<iostream> using namespace std; long long T,H,W; long long gcd(long long a,long long b){ if(b==0)return a; return gcd(b,a%b); } int main(){ cin>>T; for(int i=0;i<T;i++){ cin>>H>>W; int B=gcd(H,W); H/=B;W/=B; if((H+W)%2==1){cout<<"1 1"<<endl;} else{cout<<(H*W+1)/2<<' '<<(H*W-1)/2<<endl;} } return...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for (lli i=(a);i<(b);i++) #define RFOR(i,a,b) for (lli i=(b)-1;i>=(a);i--) #define REP(i,n) for (lli i=0;i<(n);i++) #define RREP(i,n) for (lli i=(n)-1;i>=0;i--) #define ALL(a) (a).begin(),(a).end() const int INF = INT_MAX/3; const double EPS = 1e-14; tem...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include "bits/stdc++.h" using namespace std; #define int long long #define rep(i,a,b) for(int i=(a);i<(b);i++) #define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--) #define all(a) (a).begin(),(a).end() #define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;} #define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <fstream> #include <iostream> #include <iomanip> #include <vector> #include <cmath> #include <string> #include <algorithm> #include <functional> using namespace std; #define REP(i,n) for(int i = 0; i < (n); ++i) #define FOR(i,s,n) for(int i = (s); i < (n); ++i) typedef long long ll; ll gcd(ll a, ll b) { ll...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include "bits/stdc++.h" using namespace std; //int N,M,K,L,R,H,W; long long int N,M,K,L,R,H,W; //constexpr long long int MOD=1000000007; //constexpr int MOD=1000000007; constexpr int MOD=998244353; //constexpr long long int MOD=998244353; long long int gcd(long long int a,long long int b){ while(b){ a%=b; sw...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef complex<double> P; #define REP(i,n) for(int i=0;i<n;++i) #define REPR(i,n) for(int i=1;i<n;++i) #define DEBUG(x) cout<<#x<<": "<<x<<endl #define DEBUG_VEC(v) REP(i,v.size())cout<<#v<<"["<<i<<"]:...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include<stdio.h> #include<math.h> #include<algorithm> #include<queue> #include<deque> #include<string> #include<string.h> #include<vector> #include<set> #include<map> #include<stdlib.h> using namespace std; const long long mod=1000000007; const long long inf=mod*mod; const long long d2=500000004; int gcd(int a,int b){...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#define _USE_MATH_DEFINES #include <algorithm> #include <cstdio> #include <functional> #include <iostream> #include <cfloat> #include <climits> #include <cstdlib> #include <cstring> #include <cmath> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #i...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <iostream> #include <iomanip> #include <cstdio> #include <string> #include <cstring> #include <deque> #include <list> #include <queue> #include <stack> #include <vector> #include <utility> #include <algorithm> #include <map> #include <set> #include <complex> #include <cmath> #include <limits> #include <cfloat>...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <string> #include <vector> #include <array> #include <memory> #include <iostream> #include <algorithm> using namespace std; int main(void) { //boost::shared_ptr<vector<string>> log(boost::make_shared<vector<string>>()); //log->push_back("dd"); //log->push_back("dde"); //boost::shared_ptr<vector<string>>...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <stdio.h> #include <cmath> #include <algorithm> #include <cfloat> #include <stack> #include <queue> #include <vector> #include <string> #include <iostream> #include <set> #include <map> #include <time.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define MOD 100000...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; long long int MOD = 1e9 + 7; lon...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <iostream> #include <vector> #include <algorithm> #include <iomanip> using namespace std; typedef long long int lli; lli gcd(lli a, lli b){ if(a%b==0) return b; return gcd(b,a%b); } int main(){ int t; cin >> t; for(int rep=0; rep<t; rep++){ lli h,w; cin >> h >> w; lli d = gcd(h,w); h /= d; w /=...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
import java.util.Scanner; /** * D : ???????¨??§? / Checkered Pattern */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String line; int T = sc.nextInt(); for (int i = 0; i < T; i++) { long h = sc.nextLong(); long w = sc.nextLong(); long gcd = gc...
JAVA
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include<iostream> #include<vector> #include<string> #include<algorithm> #include<map> #include<set> #include<utility> #include<cmath> #include<cstring> #include<queue> #include<cstdio> #include<sstream> #include<iomanip> #define loop(i,a,b) for(int i=a;i<b;i++) #define rep(i,a) loop(i,0,a) #define pb push_back #defi...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <bits/stdc++.h> using namespace std; const int inf=1e9; const int mod=1e9+7; typedef long long ll; typedef vector<int> vi; typedef string::const_iterator State; map<string,bool> mp; string board[15]; int T; ll gcd(ll a,ll b) { if(b>a) swap(a,b); if(a%b==0) return b; else return gcd(b,a%b); } int main(int...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <cstdio> #include <iostream> #include <sstream> #include <fstream> #include <iomanip> #include <algorithm> #include <cmath> #include <string> #include <vector> #include <list> #include <queue> #include <stack> #include <set> #include <map> #include <bitset> #include <numeric> #include <limits> #include <climit...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#define _USE_MATH_DEFINES #include <cstdio> #include <cstdlib> #include <iostream> #include <cmath> #include <cstring> #include <algorithm> #include <vector> #include <queue> #include <map> using namespace std; typedef pair<long long int, long long int> P; long long int INF = 1e18; long long int MOD = 1e9 + 7; lon...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include <cstdio> #include <cstdint> #include <algorithm> #include <utility> intmax_t gcd(intmax_t m, intmax_t n) { while (n) std::swap(m %= n, n); return m; } int solve_testcase() { intmax_t h, w; scanf("%jd %jd", &h, &w); if (h == w) return puts("1 0"), 0; intmax_t g = gcd(h, w); h /= g; w /= ...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_DEPRECATE #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <limits> #include <ctime> #include <cassert> #include <map> #include <set> #include <iostream> #include <memory> #include <string> #include <vector> #include <algorithm> #include...
CPP
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
def gcd(a,b): if a == 0: return b else: return gcd(b%a,a) t = int(input()) while t: t -= 1 a,b = map(int, input().split()) c = gcd(a,b) a = a//c b = b//c if a == b: ans1 = 1 ans2 = 0 elif a % 2 == 0 or b % 2 == 0: ans1 = 1 ans2 = 1 ...
PYTHON3
p01855 Checkered Pattern
Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (i, j), (i, j) is i + j. If is even, it is painted red, and if it is odd, it...
7
0
#include "bits/stdc++.h" using namespace std; long long int gcd(long long int l, long long int r) { assert(l > 0 && r > 0); if (l > r)return gcd(r, l); else { const long long int num = r%l; if (num) { return gcd(l, num); } else { return l; } } } int main() { int T; cin >> T; while (T--) { long...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> using namespace std; const int MAXN = 100010; int main(){ int n,q; cin >> n >> q; int a[n+1]; for(int i=0;i<n;i++){ cin >> a[i]; } int pos[n+1], push_i = n, begin_i = 0; for(int i=0;i<n;i++) pos[a[i]] = i; int query; for(int i=0;i<q;i++){ ...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define pb push_back #define l first #define r second using pi = pair<int,int>; int main(){ int n,Q; cin >>n >>Q; vector<int> x(n); rep(i,n) cin >>x[i]; int H = n+1, T = n+2; vector<pi> a(n+3);...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> using namespace std; typedef long long LL; #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define REC(ret, ...) std::function<ret (__VA_ARGS__)> template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; retur...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> #include<random> using namespace std; using ll=long long; using ld=long double; using P=pair<ll,ll>; #define MOD 1000000007LL #define INF 1000000000ll #define EPS 1e-10 #define FOR(i,n,m) for(ll i=n;i<(ll)m;i++) #define REP(i,n) FOR(i,0,n) #define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size(...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; int n,q; int a[100005]; int f[100005],t[100005]; int s,g; int main(void){ scanf("%d%d",&n,&q); for(int i=0;i<n;i++){ scanf("%d",&a[i]); } s=a[0]; g=a[n-1]; for(int i=0;i+1<n;i++){ t[a[i]]=a[i+1]; } for(int i=0;i+1<n;i++){ f[a[i+1]]=a[i]; //printf("%d %d\...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 100005 struct LIST{ int next_value,pre_value; }; LIST info[NUM]; //★★インデックスではなく値基準★★ in...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<iostream> #include<string> #include<algorithm> #include<vector> #include<iomanip> #include<math.h> #include<complex> #include<queue> #include<deque> #include<stack> #include<map> #include<set> #include<bitset> using namespace std; #define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i ) #define rep(i,n) REP(i...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<iomanip> #include<limits> #include<thread> #include<utility> #include<iostream> #include<string> #include<algorithm> #include<set> #include<map> #include<vector> #include<stack> #include<queue> #include<cmath> #include<numeric> #include<cassert> #include<random> #include<chrono> #include<unordered_map> #includ...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> using namespace std; using Int = long long; //INSERT ABOVE HERE signed main(){ Int n,q; cin>>n>>q; vector<Int> A(n),B(q); for(Int i=0;i<n;i++) cin>>A[i]; for(Int i=0;i<q;i++) cin>>B[i]; if(n==1){ cout<<1<<endl; return 0; } vector<Int> L(n+1,0),R(n+1,0); for(Int i=0;...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <algorithm> #include <iostream> #include <vector> using namespace std; template<typename T> struct List { struct Node { Node *prev, *next; T data; Node(Node* prev = nullptr, Node* next = nullptr, T data = T()) : prev(prev), next(next), data(data) { } }; Node *head, ...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; int n, q, head, last; int pre[100005] = {0}; int suf[100005] = {0}; void solve(int x); int main() { int bf; cin >> n >> q; if(n == 1) { cout << 1 << endl; return 0; } for(int i = 0; i < n; ++i) { int x; cin >> x; if(i == 0) { head = x;...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include "iostream" #include "climits" #include "list" #include "queue" #include "stack" #include "set" #include "functional" #include "algorithm" #include "string" #include "map" #include "unordered_map" #include "unordered_set" #include "iomanip" #include "cmath" #include "random" #include "bitset" #include "cstdio" ...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<deque> #include<queue> #include<vector> #include<algorithm> #include<iostream> #include<set> #include<cmath> #include<tuple> #include<string> #include<chrono> #include<functional> #include<iterator> #include<random> #include<unordered_set> #include<array> #include<map> #include<iomanip> #include<assert.h> #inc...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG_MODE #define DBG(n) n; #else #define DBG(n) ; #endif #define REP(i,n) for(ll (i) = (0);(i) < (n);++i) #define PB push_back #define MP make_pair #define FI first #define SE second #define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << end...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <stdio.h> int a[100001]; int pos[100000]; void swap(int *x, int *y) { int tmp = *x; *x = *y; *y = tmp; } int main() { int n, q; scanf("%d %d", &n, &q); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); a[i]--; pos[a[i]] = i; } int k = n; while (q--) { int b; scanf("%d",...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; using int64 = long long; int main() { int N, Q; cin >> N >> Q; vector< int > A(N); const int SQ = 333; for(int i = 0; i < N; i++) { cin >> A[i]; --A[i]; } vector< int > pending; for(int i = 0; i < Q; i++) { int q; cin >> q; --q; p...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <cstdio> #include <cstdint> #include <cstddef> #include <algorithm> #include <utility> #include <memory> #include <array> constexpr intmax_t operator ""_jd(unsigned long long n) { return n; } constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; } constexpr size_t operator ""_zu(unsigned lo...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
# -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) N, _ = inpl() A = inpl() if N == 1: print(*A) exit() L = [0]*(N+1) R = [0]*(N+1) for i in range(N-1): R[A[i]] = A[i+1] L[A[i+1]] = A[i] lm = A[0] rm = A[-1] for q in inpl(): if q == rm: l = L[q] ...
PYTHON3
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; } template<c...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <iostream> #include <string> using namespace std; int nex[100005],pre[100005]; int a[100005]; int head = 0,tail; int n, q, tmp1, tmp2; void print(){ int p=nex[head]; int a=0; while( p != tail){ if(a)cout<<' '; a++; cout<<p; p=nex[p]; } cout<<endl; } int main(void){ cin >> n >> q; if(n == 1)...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> using namespace std; //type typedef long long ll; #define pii pair<int, int> #define vi vector<int> //x * y * 1.0 can cause overflow //constant #define inf (int)(1e9+7) #define mod (ll)(1e9+7) #define eps 1e-10 //omission #define eb emplace_back #define F first #define S second #define SZ(x) ((i...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <iostream> #include <vector> using namespace std; struct node { int val; node *left, *right; node() : val(-1), left(NULL), right(NULL) { } }; void print(node* cur) { while (cur != NULL) { cout << cur->val + 1; if (cur->right) cout << " "; cur = cur->right; } co...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> #define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME #define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl #define pr1(a) (#a)<<"="<<(a)<<" " #define pr2(a,b) pr1(a)<<pr1(b) #define pr3(a,b,c) pr1(a)<<pr2(b,c) #define pr4(a,b,c,d) pr1(a)<<pr3(b,c,...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int q = sc.nextInt(); DoubleList[] lists = new DoubleList[n]; for (int i = 0; i < n; i++) { lists[i] = new DoubleList(i); ...
JAVA
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<iostream> #include<vector> using namespace std; int n,Q; struct p{ int l,r; p*next; }; int main() { cin>>n>>Q; vector<int>a(n),id(n); for(int i=0;i<n;i++) { cin>>a[i]; id[--a[i]]=i; } p*root=(p*)calloc(1, sizeof(struct p)); root->l=0,root->r=n; for(int i=0;i<Q;i++) { int q;cin>>q;q--; p*now=...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; const double PI = 3.1415926535897932384626433832795; const ll MOD = 1000000007; const int dx[] = { 0, 1, 0, -1 }; const int dy[] = { -1, 0, 1, 0 }; int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); } ll gcd(ll x, l...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
/* -*- coding: utf-8 -*- * * 2890.cc: Pivots */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; #define REP(i,n) for(int i=0;i<(int)(n);i++) #define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++) int n,q; int a[125252]; int bef[125252], aft[125252]; int main(){ scanf("%d%d",&n,&q); REP(i,n)scanf("%d",a+i),a[i]--; if(n==1){ printf("%d\n",a[0]+1); retu...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i=0;i<int(n);i++) #define rep1(i,n) for(int i=1;i<=int(n);i++) #define debug(x) cerr<<#x<<": "<<x<<endl int main(){ int n,Q; cin>>n>>Q; vector<int> a(n+2), pre(n+2), nxt(n+2), q(Q); rep1(i,n){ cin>>a[i]; } rep(i,Q) ...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include <bits/stdc++.h> #include<iostream> #include<cstdio> #include<vector> #include<queue> #...
CPP
p01990 Pivots
B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (1 \ leq q_i \ leq N) is given. In the permutation \\ {a_1, a_2, ..., a_N \\...
7
0
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long lo...
CPP
p02136 Manhattan Bomb
Problem There are $ n $ bombs on a two-dimensional plane. Each bomb is numbered from 1 to $ n $, and the $ i $ th bomb is located at coordinates $ (x_i, y_i) $. It is known that all bombs have the same Manhattan distance from the origin. When the $ i $ th bomb explodes, the bombs that are within $ r_i $ in Manhattan f...
7
0
#include <iostream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> #include <algorithm> #include <numeric> #include <random> #include <vector> #include <array> #include <bitset> #include <queue> #include <set> #include <unordered_set> #include <map> #include <unordered_map...
CPP
p02136 Manhattan Bomb
Problem There are $ n $ bombs on a two-dimensional plane. Each bomb is numbered from 1 to $ n $, and the $ i $ th bomb is located at coordinates $ (x_i, y_i) $. It is known that all bombs have the same Manhattan distance from the origin. When the $ i $ th bomb explodes, the bombs that are within $ r_i $ in Manhattan f...
7
0
#include<bits/stdc++.h> using namespace std; using Int = long long; template <typename T,typename E> struct SegmentTree{ using F = function<T(T,T)>; using G = function<T(T,E)>; Int n; F f; G g; T ti; vector<T> dat; SegmentTree(){}; SegmentTree(Int n_,F f,G g,T ti): f(f),g(g),ti(ti){ init(n_);...
CPP
p02277 Quick Sort
Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 ...
7
0
#include <iostream> #include <string> #include <vector> #include <algorithm> using namespace std; struct cards { int num = 0; char mrk = 'D'; int idx = 0; }; int partition(vector<cards>& ary, int p, int r) { cards x, sw; int i = 0; x = ary[r]; i = p - 1; for (int j = p;j < r;j++) { if (ary[j].num <= x.nu...
CPP