Skip to content

Commit 2ef80ed

Browse files
プロジェクト ファイルを追加します。
1 parent 9713fc4 commit 2ef80ed

File tree

5 files changed

+322
-0
lines changed

5 files changed

+322
-0
lines changed

Diff for: DataStructure.sln

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.7.34018.315
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DataStructure", "DataStructure\DataStructure.vcxproj", "{50E36D94-8834-4B3F-BA33-8E500522F7ED}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Debug|x64.ActiveCfg = Debug|x64
17+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Debug|x64.Build.0 = Debug|x64
18+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Debug|x86.ActiveCfg = Debug|Win32
19+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Debug|x86.Build.0 = Debug|Win32
20+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Release|x64.ActiveCfg = Release|x64
21+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Release|x64.Build.0 = Release|x64
22+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Release|x86.ActiveCfg = Release|Win32
23+
{50E36D94-8834-4B3F-BA33-8E500522F7ED}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {483501EF-A280-4DED-8DBE-5F1B7202098B}
30+
EndGlobalSection
31+
EndGlobal

Diff for: DataStructure/DataStructure.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
#include "Segtree.h"
5+
6+
int op(int a, int b) {
7+
return min(a, b);
8+
}
9+
int e() {
10+
return INT_MAX;
11+
}
12+
13+
14+
int main() {
15+
int N, Q;
16+
cin >> N >> Q;
17+
segtree<int, op, e> ST(N);
18+
for (int i = 0; i < N; i++) {
19+
int in;
20+
cin >> in;
21+
ST.set(in, i);
22+
}
23+
24+
for (int q = 0; q < Q; q++) {
25+
int l, r;
26+
cin >> l >> r;
27+
cout << ST.prod_NotRecursive(l, r) << endl;
28+
}
29+
}

Diff for: DataStructure/DataStructure.vcxproj

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<VCProjectVersion>17.0</VCProjectVersion>
23+
<Keyword>Win32Proj</Keyword>
24+
<ProjectGuid>{50e36d94-8834-4b3f-ba33-8e500522f7ed}</ProjectGuid>
25+
<RootNamespace>DataStructure</RootNamespace>
26+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
27+
</PropertyGroup>
28+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
29+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
30+
<ConfigurationType>Application</ConfigurationType>
31+
<UseDebugLibraries>true</UseDebugLibraries>
32+
<PlatformToolset>v143</PlatformToolset>
33+
<CharacterSet>Unicode</CharacterSet>
34+
</PropertyGroup>
35+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
36+
<ConfigurationType>Application</ConfigurationType>
37+
<UseDebugLibraries>false</UseDebugLibraries>
38+
<PlatformToolset>v143</PlatformToolset>
39+
<WholeProgramOptimization>true</WholeProgramOptimization>
40+
<CharacterSet>Unicode</CharacterSet>
41+
</PropertyGroup>
42+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
43+
<ConfigurationType>Application</ConfigurationType>
44+
<UseDebugLibraries>true</UseDebugLibraries>
45+
<PlatformToolset>v143</PlatformToolset>
46+
<CharacterSet>Unicode</CharacterSet>
47+
</PropertyGroup>
48+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
49+
<ConfigurationType>Application</ConfigurationType>
50+
<UseDebugLibraries>false</UseDebugLibraries>
51+
<PlatformToolset>v143</PlatformToolset>
52+
<WholeProgramOptimization>true</WholeProgramOptimization>
53+
<CharacterSet>Unicode</CharacterSet>
54+
</PropertyGroup>
55+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
56+
<ImportGroup Label="ExtensionSettings">
57+
</ImportGroup>
58+
<ImportGroup Label="Shared">
59+
</ImportGroup>
60+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
61+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62+
</ImportGroup>
63+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
65+
</ImportGroup>
66+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
67+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
68+
</ImportGroup>
69+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
70+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
71+
</ImportGroup>
72+
<PropertyGroup Label="UserMacros" />
73+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
74+
<ClCompile>
75+
<WarningLevel>Level3</WarningLevel>
76+
<SDLCheck>true</SDLCheck>
77+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
78+
<ConformanceMode>true</ConformanceMode>
79+
</ClCompile>
80+
<Link>
81+
<SubSystem>Console</SubSystem>
82+
<GenerateDebugInformation>true</GenerateDebugInformation>
83+
</Link>
84+
</ItemDefinitionGroup>
85+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
86+
<ClCompile>
87+
<WarningLevel>Level3</WarningLevel>
88+
<FunctionLevelLinking>true</FunctionLevelLinking>
89+
<IntrinsicFunctions>true</IntrinsicFunctions>
90+
<SDLCheck>true</SDLCheck>
91+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
92+
<ConformanceMode>true</ConformanceMode>
93+
</ClCompile>
94+
<Link>
95+
<SubSystem>Console</SubSystem>
96+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
97+
<OptimizeReferences>true</OptimizeReferences>
98+
<GenerateDebugInformation>true</GenerateDebugInformation>
99+
</Link>
100+
</ItemDefinitionGroup>
101+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
102+
<ClCompile>
103+
<WarningLevel>Level3</WarningLevel>
104+
<SDLCheck>true</SDLCheck>
105+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
106+
<ConformanceMode>true</ConformanceMode>
107+
</ClCompile>
108+
<Link>
109+
<SubSystem>Console</SubSystem>
110+
<GenerateDebugInformation>true</GenerateDebugInformation>
111+
</Link>
112+
</ItemDefinitionGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<FunctionLevelLinking>true</FunctionLevelLinking>
117+
<IntrinsicFunctions>true</IntrinsicFunctions>
118+
<SDLCheck>true</SDLCheck>
119+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
120+
<ConformanceMode>true</ConformanceMode>
121+
</ClCompile>
122+
<Link>
123+
<SubSystem>Console</SubSystem>
124+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
125+
<OptimizeReferences>true</OptimizeReferences>
126+
<GenerateDebugInformation>true</GenerateDebugInformation>
127+
</Link>
128+
</ItemDefinitionGroup>
129+
<ItemGroup>
130+
<ClCompile Include="DataStructure.cpp" />
131+
</ItemGroup>
132+
<ItemGroup>
133+
<ClInclude Include="Segtree.h" />
134+
</ItemGroup>
135+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
136+
<ImportGroup Label="ExtensionTargets">
137+
</ImportGroup>
138+
</Project>

Diff for: DataStructure/DataStructure.vcxproj.filters

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="ソース ファイル">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="ヘッダー ファイル">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="リソース ファイル">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="DataStructure.cpp">
19+
<Filter>ソース ファイル</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClInclude Include="Segtree.h">
24+
<Filter>ヘッダー ファイル</Filter>
25+
</ClInclude>
26+
</ItemGroup>
27+
</Project>

Diff for: DataStructure/Segtree.h

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#pragma once
2+
3+
#include <vector>
4+
5+
template<class S, S(*op)(S, S), S(*e)()>
6+
class segtree {
7+
public:
8+
segtree(size_t size) {
9+
// size以上の2^kとなる最小のkを求め,2^(k+1)で配列サイズを決定する.(配列の最後の1要素は使用しない)
10+
uint32_t k = (size == 1) ? 1u : (uint32_t)log2((double)(size - 1u)) + 1;
11+
_n = (1 << (k + 1));
12+
_data.resize(_n, e());
13+
}
14+
15+
void set(S x, int pos) {
16+
// seg-treeにおいて,元の配列[pos]はsegtree[_n/2 - 1 + pos]にある.
17+
// おおもとの場所から処理していく.
18+
int looking = _n / 2 - 1 + pos;
19+
_data[looking] = x;
20+
// 根の方に更新していく.
21+
// lookingが奇数であれば右側と,偶数であれば左側と演算する.
22+
// 親は(looking-1)/2である.
23+
while (looking != 0) {
24+
if (looking % 2 == 0) {
25+
x = op(_data[looking - 1], x);
26+
}
27+
else {
28+
x = op(x, _data[looking + 1]);
29+
}
30+
looking = (looking - 1) / 2;
31+
if (_data[looking] == x) {
32+
break;
33+
}
34+
_data[looking] = x;
35+
}
36+
}
37+
// query([l, r))
38+
S prod(int l, int r) {
39+
S val = e();
40+
_prod_recursive(l, r, 0, 0, val);
41+
42+
return val;
43+
}
44+
// query[l, r)
45+
S prod_NotRecursive(int l, int r) {
46+
l += _n / 2 - 1;
47+
r += _n / 2 - 1;
48+
S val_l = e();
49+
S val_r = e();
50+
51+
while (l < r) {
52+
if ((l & 1) == 0) {
53+
val_l = op(val_l, _data[l]);
54+
l++;
55+
}
56+
if ((r & 1) == 0) {
57+
r--;
58+
val_r = op(_data[r], val_r);
59+
}
60+
l = (l - 1) >> 1;
61+
r = (r - 1) >> 1;
62+
}
63+
64+
return op(val_l, val_r);
65+
}
66+
67+
private:
68+
size_t _n;
69+
vector<S> _data;
70+
71+
void _prod_recursive(int l, int r, int NodeID, int depth, S& val) {
72+
// Nodeの,現在のDepthでの左から何個めのNodeであるか
73+
int CurDepthNodeID = NodeID - ((1 << depth) - 1);
74+
int CurDepthNodeWidth = _n / 2 / (1 << depth);
75+
// [RangeL, RangeR): 現在注目しているNodeが網羅しているRange
76+
int CurNodeRangeL = CurDepthNodeWidth * CurDepthNodeID;
77+
int CurNodeRangeR = CurDepthNodeWidth * (CurDepthNodeID + 1);
78+
79+
// [RangeL, RangeR) AND [l, r) が空集合の場合(区間が一切被らない場合)
80+
// 何もしない
81+
if (CurNodeRangeR <= l || r <= CurNodeRangeL) {
82+
return;
83+
}
84+
// [RangeL, RangeR) AND [l, r) が[RangeL, RangeR)の場合
85+
// 左から注目しているので左にvalを置く
86+
else if (l <= CurNodeRangeL && CurNodeRangeR <= r) {
87+
val = op(val, _data[NodeID]);
88+
return;
89+
}
90+
// 2区間がお互いに一部だけ被っている場合
91+
// 左から子ノードを見ていく
92+
else {
93+
_prod_recursive(l, r, NodeID * 2 + 1, depth + 1, val);
94+
_prod_recursive(l, r, NodeID * 2 + 2, depth + 1, val);
95+
}
96+
}
97+
};

0 commit comments

Comments
 (0)